7

I want to run a script on windows dos terminal where the script will display "Hello world" to the terminal I executed this from e.g.

matlab.exe -nosplash -nodesktop -nojvm -wait -r printToCommandLine.m

Where printToCommandLine.m contains:

system(sprintf('echo Hello world'));

but it only prints to the matlab command window that gets generated when executing the script

8
  • 2
    I don't think this behavior is supported on Windows. See here. Commented Mar 9, 2018 at 5:56
  • Hmm.. is there any way to notify the command line of anything? I basically have a very long Matlab script and I want to display when a certain process is finished e.g. "Process A is complete..." Commented Mar 9, 2018 at 6:29
  • Alternative 1: install Linux. Alternative 2: use Octave. Sorry I don't have any better news for you. Commented Mar 9, 2018 at 6:52
  • @kkawabat Wrap the call to Matlab in its own executable that prints a string when it's finished? Commented Mar 9, 2018 at 7:36
  • @AnonSubmitter85 I want to print a string in the middle of the Matlab file since it's one script but has multiple parts within the script. I can separate the processes into different scripts and wrap those in but that would be difficult for my case. Commented Mar 9, 2018 at 8:08

1 Answer 1

2

First, I am not shure, if the syntax has changed, but I have to call the script without the file extension '.m':

matlab.exe -nosplash -nodesktop -nojvm -wait -r printToCommandLine

Otherwise I will get an error within MATLAB.

Second, this is just a work around, but you can print your current command line output to a log file e.g. 'log.txt' using

matlab.exe -nosplash -nodesktop -nojvm -wait -logfile "log.txt" -r printToCommandLine

The log file will be updated at runtime. To test this, I created a small example script and had a look how 'log.txt' changes during execution:

disp('Script execution started. Waiting 10 seconds...')
pause(10)
disp('...waited 10 seconds.');

This is not exactly what you wanted but it gives you the chance to get actual information about the current command line output during your execution (in a text file).

We use this for automated (remote) testing to print our MATLAB command line output to the console after the tests pass with

type log.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.