Print command window output on command prompt of windows (cmd)
Show older comments
Hey everyone,
I hope you all are in good health.
I have a question about how to automatically write everything that displays on command windows simultaneously on the command prompt of windows (cmd).
here is what I have found for storing the command window of Matlab to a file and then publishing it as an HTML file to the browser,
myFile = 'commandWindowText.txt';
if exist(myFile, 'file')==2
delete(myFile);
end
diary(myFile)
diary on
% ---- || what i want to display in the command window
syms x
eq = 'x^4 + 2*x + 1';
s = solve(x^4 + 2*x + 1, x,'MaxDegree',3);
disp(['the equation is: ' eq])
disp(['and the result is: ' ])
pretty(s)
diary off
% ---- || open the file to get the content as a string
fid = fopen(myFile,'r');
f=fread(fid,'*char')';
fclose(fid);
% ---- || adapt the text file to html
f=strrep(f,'\','\\'); % thanks to mahoromax's comment (accomodates windows file paths)
f=strrep(f,newline,'<br>');
f=strrep(f,' ',' ');
f=['<p style = "font-family:monospace" >',newline,f,newline,'</p>'];
% ---- || write the file and view it on the broweser
fid=fopen('diary_file.html','w');
fprintf(fid,f);
fclose(fid);
winopen('diary_file.html') % windows only?
in addition to the HTML version i need to send this information to the cmd of windows, but i dont know how
1- open command prompt
2 - send text to command prompt.
any help appreciated.
6 Comments
Rik
on 4 Jul 2021
What is your goal in sending that text? Do you just want to display it (with echo)? Or do you want to run some command?
Matlab is generally not the best tool to send keystrokes to external programs. If that is your goal you might consider pasting to the clipboard (see the clipboard function).
Abolfazl Nejatian
on 4 Jul 2021
Rik
on 4 Jul 2021
Do you need the command prompt to be interactive afterward? Because I'm not aware of a way to do that. And should it be a specific window, or can it be any cmd window?
Note that the term shell generally means a Unix prompt, which you can get on windows with WSL.
Abolfazl Nejatian
on 4 Jul 2021
dpb
on 4 Jul 2021
"I want to create a stand-alone app with an app designer and I need to show some progress..."
App Designer doesn't built a console; use something like a progress bar or whatever controls in the app widget collection instead.
Don't try to pound a square peg into a round hole; the way you're trying to go is not going to be satisfactory even if you can manage to cobble something together.
Abolfazl Nejatian
on 5 Jul 2021
Edited: Abolfazl Nejatian
on 5 Jul 2021
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!