Formatting .txt files as the one produced by command prompt.

1 回表示 (過去 30 日間)
Ajpaezm
Ajpaezm 2020 年 1 月 31 日
回答済み: Stephen23 2020 年 1 月 31 日
Hi, I have the following script that requests all processes running currently on my machine.
[~,tasks] = system('tasklist');
fileID = fopen('another_test.txt','w');
fprintf(fileID,'%s',tasks);
fclose(fileID);
The file looks like this:
upload1.JPG
If I try the same thing on the Windows Command Prompt, using this command:
tasklist.exe > %USERPROFILE%\Desktop\processlog.txt
Which gets me this in a nice format which I can't replicate using Matlab. And I would like to get it in the same way, or somewhat similar at least.
Upload2.JPG
The use of delimiters perhaps could help? Any guidance would be great, thanks in advance.

採用された回答

Stephen23
Stephen23 2020 年 1 月 31 日
Open the file in text mode:
fileID = fopen('another_test.txt','wt');
% ^ you need this!
and use a proper text editor, e.g. Notepad++.

その他の回答 (1 件)

Bhaskar R
Bhaskar R 2020 年 1 月 31 日
You can include same input to system command
sts = system('tasklist.exe > %USERPROFILE%\Desktop\processlog.txt');
This works as you require

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by