How can I detect end of lines in a output string of a dos command?
5 次查看(过去 30 天)
显示 更早的评论
I execute e.g.:
>> [status, cmdout] = dos(['tracert www.google.com']);
>> cmdout
When I copy the output of the Matlab command window and paste it into Notepad++, I see a CR and LF at the end of each line. Finding these with strfind does not return what I expect:
>> strfind(cmdout,'\r\f')
ans =
[]
How can I divide the cmdout string into individual lines?
0 个评论
采纳的回答
Friedrich
2014-1-20
编辑:Friedrich
2014-1-20
Hi,
try
lines = regexp(cmdout,'\n','split')
Or
lines = textscan(cmdout,'%s','delimiter','\n')
However you will get a few empty lines because of the way the cmdout is generated. Sometimes you have two newline indicators before an actual line. But this should help get started.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!