Print command window output on command prompt of windows (cmd)

68 visualizaciones (últimos 30 días)
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,' ','&nbsp');
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 comentarios
dpb
dpb el 4 de Jul. de 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
Abolfazl Nejatian el 5 de Jul. de 2021
Editada: Abolfazl Nejatian el 5 de Jul. de 2021
Dear @dpb
thank you for your explanation,
I understood what you try to transfer to me.
just forget about the app designer.
so you told me there is no logical way to paste/display something in the command prompt from Matlab Neither with Matlab routine code nor with existing Matlab-java codes.
I'm disappointed :/

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Jul. de 2021
If you are using Windows then use .NET controls System.Diagnostics.Process to create a link to either PowerShell or CMD.exe. Anything that you write to the end point will then be sent to the process to be executed (or interpreted as input).
However, I do not understand how executing the matlab output as shell commands will be beneficial in any way. But that is what pasting the output to the command prompt means, that you want the output to be executed as commands.
  8 comentarios
Walter Roberson
Walter Roberson el 5 de Jul. de 2021
MATLAB can run the GoLANG process, using System.Diagnostics.Process . Or GoLANG can run MATLAB and read its standard output and standard error. Or something else could invoke each of them and take care of merging the outputs.
Note that in MATLAB if you fopen() a file with 'a' access, then every fprintf() or fwrite() to the file will result in a fseek() to end of file, even if a different program is writing to the same file . So if you were careful to do things like
NOW = char(datetime('now', 'Format', 'yyyyMMdd HH:mm:ss.SSS'));
fprintf(fid, 'AN7: %s: error coefficient is %.5g\n', NOW(), slice_err);
which writes an entire (time-stamped) line, then the operating system would guarantee that it will appear as a line by itself, not scrambled up with output from the GoLang program.
Abolfazl Nejatian
Abolfazl Nejatian el 6 de Jul. de 2021
thank you for your consideration.
i will try to call Matlab scrip from my GoLang. i think it is the best soulution for me.
kind regards,
Abolfazl

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by