MATLAB 系统命令 "Press Enter to Exit"

MATLAB System Command "Press Enter to Exit"

我正在尝试编写一个 MATLAB 脚本来调用 运行 一个外部程序,然后继续执行其他 MATLAB 命令。

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

但是,这个程序 "MyProgram.exe" 需要我 "Press Enter to Exit." 如何让我的 MATLAB 脚本通过 "Enter" 才能继续?比如如何在执行结束时将 "Enter" 作为程序的输入传递?或者一般如何做到这一点?

UNIX 上,您可以使用

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

Matlab documentation 中所建议:

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

Windows等价于(基于this post):

system('MyProgram.exe < NUL')

当控制台程序需要从用户那里获取一次输入并且没有内置的方法(比如将其作为参数传递)时,可以 echoed 并且管道到程序。这也可以用于通过管道空行按 Enter(再次,一次)。

echo.|program.exe

传统上,使用命令 echo. 时,echo 会生成一个空行,但如果当前目录包含名为 echo 且没有扩展名的文件,则此操作可能会失败。要解决此问题,您可以使用 ( 而不是 ..

echo(|program.exe