Pass the content of a variable to a .bat file from matlab

조회 수: 1 (최근 30일)
luigi luigi
luigi luigi 2016년 2월 13일
편집: dpb 2016년 2월 14일
Sorry, I have a new problem. I have this char variable: name='file.pdf';
when I do !test name
I see in the file test.bat "name", that is the container of the variabile but not the content of the variable.....I need to pass the content name.pdf to the file test.bat.
How can I resolve?? How cas I pass the string name.pdf to the .bat?

답변 (1개)

dpb
dpb 2016년 2월 13일
편집: dpb 2016년 2월 14일
Use system instead for command form to evaluate variables in building the command string. ! ("Bang") interprets everything after it as character string so doesn't (as you've discovered) evaluate the variable before passing it to the OS.
>> f='c*.m'; % selected list of m-files in variable
>> [~,res]=system(['dir /b ' f]) % do a command; "dir" in the example...
res =
categorizeDesignated.m
currenteval.m
>>
ADDENDUM
Just do it again...
system(['report.bat ' res])
Or, more likely you'd want in real life something like
system(['report.bat <dir /b ' f])
Build the string that are going to submit just as you would any other string in Matlab; the limitation is that must(*) use the functional form instead of the bang operator to get a variable interpreted.
() without resort to evil *eval, which route I'm not going to suggest...albeit under some circumstances it is useful.
  댓글 수: 1
luigi luigi
luigi luigi 2016년 2월 14일
thanks but now how I can pass to file report.bat the content of the variable "res"? sorry for my problems!

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by