필터 지우기
필터 지우기

Issue in executing command containing single quote using Plink

조회 수: 7 (최근 30일)
tafteh
tafteh 2018년 8월 20일
편집: tafteh 2018년 8월 21일
I am using plink.exe from cmd in Windows 10, to ssh to Ubuntu 16.04. In there, I am running MATLAB, to run the following command:
try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end
For this, I generate the following command to handle ssh, executing matlab and run the above command:
C:\plink.exe user@server -pw ****** "matlab -nodesktop -nosplash -noawt -r 'try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end'
Running the above command, I get the following error in MATLAB:
Warning: Undefined function or variable 'path/to/files'.
As it turns out, in MATLAB, the command is constructed like following:
someFunction(path/to/files, algorithm)
which is without "single quotes": thank you, plink :( .
Can you please help to generate the correct command? or if there is already a question asked with similar problem, I would be thankful to direct me to it.
Thanks,

채택된 답변

tafteh
tafteh 2018년 8월 21일
편집: tafteh 2018년 8월 21일
I fixed my problem using the following solutions:
echo matlab -nodesktop -nosplash -noawt -r "try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end" | C:\plink.exe user@server -pw ****** -T
Credit goes to Martin Prikryl (https://stackoverflow.com/users/850848/martin-prikryl)

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2018년 8월 20일
편집: Fangjun Jiang 2018년 8월 21일
I would suggest putting all the commands in a M-script and then run
"fullpath\bin\matlab.exe" -r "MyScript"
Notice the double quote "
FYI, in matlab, the command is constructed like following:
someFunction('path/to/files', OtherInputArguments)
or
MyFile='path/to/files'
someFunction(MyFile, OtherInputArguments)
To create a single quote in a string, refer to the following example:
a='path/to/files'
b='''path/to/files'''
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2018년 8월 21일
See updated answer. Not sure what do you mean "does not work".
tafteh
tafteh 2018년 8월 21일
Thanks for the update. "dose not work" means that I get the same error message from MATLAB. When the following lines
a='path/to/files'
b='''path/to/files'''
are executed in MATLAB using plink.exe are still turned into
a=path/to/files
b=path/to/files
I would try putting MATLAB command in a script as you suggested.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by