MATLAB System Command “Press Enter to Exit”

可紊 提交于 2019-12-22 08:18:12

问题


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 ?


回答1:


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')



回答2:


When a console program needs to take input one time from the user and there is no built-in way to do so (like passing it in as an argument), that input can be echoed and piped to the program. This can also be used to press Enter (again, once) by piping a blank line.

echo.|program.exe

While traditionally a blank line is generated with echo by using the command echo., this can fail if the current directory contains a file called echo that has no extension. To get around this, you can use a ( instead of a ..

echo(|program.exe


来源:https://stackoverflow.com/questions/44811768/matlab-system-command-press-enter-to-exit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!