通过SSH在Windows上远程启动Matlab?不可能的? [英] Launching matlab remotely on windows via ssh? Impossible?

查看:151
本文介绍了通过SSH在Windows上远程启动Matlab?不可能的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我试图通过Cygwin安装的OpenSSH在Windows上远程运行matlab,但是在没有GUI的情况下在Windows中启动matlab似乎是不可能的.

Howdy, I am trying to run matlab remotely on windows via OpenSSH installed with Cygwin, but launching matlab in windows without the GUI seems to be impossible.

如果我在本地登录,则可以启动matlab -nodesktop -nodisplay -r脚本,然后matlab将启动精简的GUI并执行命令.

If i am logged in locally, I can launch matlab -nodesktop -nodisplay -r script, and matlab will launch up a stripped down GUI and do the command.

但是,这不可能通过ssh远程完成,因为matlab需要显示GUI.

However, this is impossible to do remotely via ssh, as, matlab needs to display the GUI.

有人有任何建议或解决方法吗?

Does anyone have any suggestions or work arounds?

谢谢

鲍勃

推荐答案

短篇小说:您的脚本调用了exit()吗?您在使用-等待"吗?

Short story: is your script calling exit()? Are you using "-wait"?

长话短说:如果您想与之互动,我认为您根本就不走运,但是如果您只是想批量处理工作,这应该可以工作. Windows上的Matlab是GUI应用程序,而不是控制台应用程序,并且不会与纯字符远程连接进行交互.但是您仍然可以启动该过程. Matlab实际上会显示GUI-它只是在您无权访问的远程计算机上的桌面会话中.但是,如果您无需更多输入就可以使它完成工作,那么对于工作"的某些价值,这可以使它起作用.

Long story: I think you're fundamentally out of luck if you want to interact with it, but this should work if you just want to batch jobs up. Matlab on Windows is a GUI application, not a console application, and won't interact with character-only remote connectivity. But you can still launch the process. Matlab will actually display the GUI - it will just be in a desktop session on the remote computer that you have no access to. But if you can get it to do your job without further input, this can be made to work, for some value of "work".

您的"-r脚本"开关是正确的方向.但是要意识到,在Windows上,Matlab的"-r"行为是完成脚本,然后返回到GUI,等待进一步的输入.您需要显式包括一个"exit()"调用以完成您的工作,并添加try/catches以确保到达exit().另外,您应该使用"-logfile"开关将所有命令窗口输出的副本捕获到日志文件中,以便您可以查看其运行情况(因为您看不到GUI),并且可以记录以前的运行情况.

Your "-r script" switch is the right direction. But realize that on Windows, Matlab's "-r" behavior is to finish the script and then go back to the GUI, waiting for further input. You need to explicitly include an "exit()" call to get your job to finish, and add try/catches to make sure that exit() gets reached. Also, you should use a "-logfile" switch to capture a copy of all the command window output to a log file so you can see what it's doing (since you can't see the GUI) and have a record of prior runs.

此外,默认情况下,matlab.exe是异步的.除非添加"-wait"开关,否则您的ssh调用将启动Matlab并立即返回.检查您要切换到的机器上的进程; Matlab可能实际上正在运行.如果希望阻止直到完成,请添加-wait.

Also, matlab.exe is asynchronous by default. Your ssh call will launch Matlab and return right away unless you add the "-wait" switch. Check the processes on the machine you're sshing to; Matlab may actually be running. Add -wait if you want it to block until finished.

一种执行此操作的方法是使用-r调用标准作业包装器脚本,该脚本初始化您的库和路径,运行作业,并执行清理和退出操作.您还需要制作一个.bat包装程序,以将-logfile开关设置为指向其中包含作业名称,时间戳和其他信息的文件.在M代码级别上是这样的.

One way to do this stuff just use -r to call to a standard job wrapper script that initializes your libraries and paths, runs a job, and does cleanup and exit. You'll also want to make a .bat wrapper that sets up the -logfile switch to point to a file with the job name, timestamp, and other info in it. Something like this at the M-code level.

function run_batch_job(jobname)
try
   init_my_matlab_library(); % By calling classpath(), javaclasspath(), etc
   feval(jobname); % assumes jobname is an M-file on the path
catch err
   warning('Error occurred while running job %s: %s', jobname, err.message)
end
try
   exit();
catch err
   % Yes, exit() can throw errors
   java.lang.System.exit(1); % Scuttle the process hard to make sure job finishes
end
% If your code makes it to here, your job will hang

之前,我已经在Windows Scheduler,Tidal和TWS中使用这种样式设置了批处理作业系统.我认为在ssh或其他远程访问下,它应该以相同的方式工作.

I've set up batch job systems using this style in Windows Scheduler, Tidal, and TWS before. I think it should work the same way under ssh or other remote access.

像这样的Windows上的Matlab批处理系统非常脆弱且难以管理.从根本上讲,Windows上的Matlab并不是要成为无头的批处理执行系统;关于交互式GUI的各种假设普遍存在,并且很难解决.低级错误或许可证错误将弹出模式对话框并挂起您的工作. Matlab的启动顺序似乎具有竞争条件.您无法设置MATLAB.exe的退出状态.无法通过Matlab GUI调试作业引发的错误.日志文件可能已被缓冲,您在挂起和崩溃时丢失了输出.依此类推.

A Matlab batch system on Windows like this is brittle and hard to manage. Matlab on Windows is fundamentally not built to be a headless batch execution system; assumptions about an interactive GUI are pervasive in it and hard to work around. Low-level errors or license errors will pop up modal dialog boxes and hang your job. The Matlab startup sequence seems to have race conditions. You can't set the exit status of MATLAB.exe. There's no way of getting at the Matlab GUI to debug errors the job throws. The log file may be buffered and you lose output near hangs and crashes. And so on.

认真考虑移植到Linux. Matlab在那里更适合作为批处理系统.

Seriously consider porting to Linux. Matlab is much more suitable as a batch system there.

如果您有金钱或备用许可证,还可以使用Matlab分布式计算工具箱和服务器在远程工作程序节点上运行代码.这可以用于并行化或远程批处理作业.

If you have the money or spare licenses, you could also use the Matlab Distributed Computing toolbox and server to run code on remote worker nodes. This can work for parallelization or for remote batch jobs.

这篇关于通过SSH在Windows上远程启动Matlab?不可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆