Search code examples
matlabbatch-filecmdenter

MATLAB System Command "Press Enter to Exit"


I am trying to write a MATLAB script that would call and run an external program and then proceed with other MATLAB commands.

tic                       %Start stopwatch
system('MyProgram.exe')   %Call and run my program
toc                       %End stopwatch 

However, this program "MyProgram.exe" requires me to "Press Enter to Exit." How to make my MATLAB script pass "Enter" to proceed? Like How to pass "Enter" as an input of my program at the end of execution? Or how to do this in general ?


Solution

  • On UNIX, you can use

    system('MyProgram < /dev/null'). 
    

    as suggested in the Matlab documentation:

    To disable stdin and type-ahead redirection, include the formatted text < /dev/null in the call to the invoked command.

    The Windows equivalent is (based on this post):

    system('MyProgram.exe < NUL')