how to store the result of a dos command into a file in matlab

Hello, I would like to store the result of the dos command into a text file, which i want to read later in matlab. i used the following code
[status, Result] = dos(Iperf_command,'-echo');
fid=fopen('result.txt','w');
fprintf(fid,'%6.2f %12.8f\n',Result);
fclose(fid);
but t didnt work out. Please help me in this regard.Thanks in advance.

 採用された回答

Walter Roberson
Walter Roberson 2013 年 10 月 14 日

0 投票

the PingLog.txt is the file the output will be written to. At least the standard output; errors might go to a different location.
But if you have already captured the result into Result, then use
fid = fopen('result.xt', 'w');
fwrite(fid, Result);
fclose(fid);

3 件のコメント

uday teja
uday teja 2013 年 10 月 14 日
i did as you said as follows
Iperf_command = get(handles.edit_iperf_command,'String');
[status, Result] = dos(Iperf_command,'-echo');
fid = fopen('output.txt', 'w');
fwrite(fid, Result);
fclose(fid);
but when i give output.txt in the command prompt i get the following error 'Undefined variable "output" or class "output.txt".'
Walter Roberson
Walter Roberson 2013 年 10 月 14 日
A file name is not a command. If you want to view the file after you create it, use an appropriate command. Perhaps
type output.txt
uday teja
uday teja 2013 年 10 月 14 日
or would this be fine
[status, Result] = dos(Iperf_command > output.txt,'-echo');
fid = fopen('output.txt', 'w');
fread(fid, Result);
fclose(fid);

サインインしてコメントする。

その他の回答 (1 件)

sixwwwwww
sixwwwwww 2013 年 10 月 14 日
編集済み: sixwwwwww 2013 年 10 月 14 日

0 投票

Dear Uday Teja, "Iperf_command" is not a valid "dos" command. You should use keyword "help" in dos command prompt to get the list of valid commands you can use in dos command prompt. For example, "ver" is a valid command then you can use "dos" command in MATLAB as:
[status, Result] = dos('ver','-echo');
Will give you version of Windows. The out result should be handled with correct formatting to write in a text file. Good luck!

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

質問済み:

2013 年 10 月 14 日

コメント済み:

2013 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by