How can I detect end of lines in a output string of a dos command?

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?

 채택된 답변

Friedrich
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

This works fine for my purpose. Thanks a lot!
As the output to dos commands differs structurally from computer to computer and also depending on the result, having the answer by line really helps for searching the required information.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Amit
Amit 2014년 1월 20일
편집: Amit 2014년 1월 20일

0 개 추천

CR and FR are carriage return and line feed. Most of the notepad type application do not show it.
The reason strfind does not find it because its not there. Have you tried pasting it in a different word processor like windows native wordpad or notepad?

카테고리

질문:

2014년 1월 20일

댓글:

2014년 1월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by