Formatting .txt files as the one produced by command prompt.
조회 수: 1 (최근 30일)
이전 댓글 표시
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269204/upload1.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269205/Upload2.jpeg)
The use of delimiters perhaps could help? Any guidance would be great, thanks in advance.
댓글 수: 0
채택된 답변
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++.
댓글 수: 0
추가 답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!