有一种使用Java的方法,特别是java.awt.Robot类。见
here。
显然,有两种类型的程序,关于从Matlab与系统(‘…’)调用时的工作方式:
>对于某些程序,Matlab等待程序在运行下一个语句之前已经完成。这发生在例如WinRAR(至少在我的Windows 7机器)中。
>对于其他程序,这不会发生,Matlab在外部程序启动后继续下一个语句。这种类型的例子是explorer(标准的Windows文件浏览器)。
现在,即使对于类型1程序,也可以立即将执行返回给Matlab:只需添加&在传递到系统的字符串的末尾。这是standard in Linux Bash shell,它也适用于Windows,如here所述。
所以,你将继续如下:
robot = java.awt.Robot;
command = '"C:\Program Files (x86)\WinRAR\WinRAR"'; %// external program; full path
system([command ' &']); %// note: ' &' at the end
pause(5) %// allow some time for the external program to start
robot.keyPress (java.awt.event.KeyEvent.VK_ENTER); %// press "enter" key
robot.keyRelease (java.awt.event.KeyEvent.VK_ENTER); %// release "enter" key