I have a linux box with MATLAB installed on it. I want to launch some MATLAB scripts on it from MATLAB on my desktop PC, but I don't want the command to block, i.e. I want the command prompt re-appear immediately, and for the command to be run asynchronously on the box. To be clear, every command I send should start a new instance of MATLAB on the linux box, and run in that. There is no communication between the two MATLABs once the command is sent.
I can do this from a linux PC fine, using:
a = round(clock);
str = sprintf('ssh cvg-1 "nohup /opt/matlab2010a/bin/matlab -nojvm -nodisplay -r \\"try, fprintf(''%s\\\\n''); %s; catch, a = lasterror(); fprintf(''??? %%s\\\\n'', a.message); end; quit;\\" -logfile ~/log/matlab.%4.4d.%2.2d.%2.2d.%2.2d.%2d.%2.2d.log >& nul &"', regexprep(cmd, '''', ''''''), cmd, a(1), a(2), a(3), a(4), a(5), a(6));
system(str);
I have saved my password so ssh is able to connect without asking for it. On my Windows PC I hope to do this through cygwin. If I copy the string str (from above) onto the cygwin command line then the command runs fine. However, to call this from MATLAB in Windows I need to call cygwin to call ssh, so there is an extra layer there. This is causing me problems. The simplest command I have tried is:
str = 'C:/cygwin/bin/bash --login -c "ssh cvg-1 \"nohup /opt/matlab2010a/bin/matlab -nojvm -nodisplay -r quit >& nul &\""';
system(str);
which produces:
>& was unexpected at this time.
At this point I'm stuck. Can anybody help?
Thanks,
Oliver
system('asynclinux.bat &')
On Sep 2, 2:08 pm, "Oliver Woodford" <o.j.woodford...@cantab.net>
wrote:
"Oliver Woodford" <o.j.woo...@cantab.net> wrote in message
news:i5op6j$bij$1...@fred.mathworks.com...
I think your four instances of double-quote " are nesting in a way other
than what you want. You might want to replace one pair of them with two
single quotes each, which will result in one single quote being included in
the string.
str = 'That''s all folks!'
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
"Steven_Lord" wrote:
> I think your four instances of double-quote " are nesting in a way other
> than what you want. You might want to replace one pair of them with two
> single quotes each, which will result in one single quote being included in
> the string.
Thanks, Steve. I ended up trying pretty much every combination of nested `, ' and " quotes, but nothing worked.
"Patrick Mineault" wrote:
> Maybe try wrapping the command in a batch file and then calling that
> batch file? Something like:
>
> system('asynclinux.bat &')
Thanks for the suggestion, Patrick.
A colleague of mine pointed out that the ssh that cygwin uses is actually an executable. I stuck the directory containing this executable (C:\cygwin\bin) on my path, and I was then able to use the same code as for linux, with no problems. The final function to run a matlab command on a remote machine (cvg-1) was:
function cvg1(cmd)
a = round(clock);
str = sprintf('ssh cvg-1 "nohup /opt/matlab2010a/bin/matlab -nojvm -nodisplay -r \\"try, fprintf(''%s\\\\n''); %s; catch ME, disp(ME.message); end; quit force;\\" -logfile ~/log/matlab.%4.4d.%2.2d.%2.2d.%2.2d.%2d.%2.2d.log >& nul &"', regexprep(cmd, '''', ''''''), cmd, a(1), a(2), a(3), a(4), a(5), a(6));
system(str);