Dos command doesn't work through Matlab, and works OK in command window

I'm trying to run an external program through a DOS command with Matlab.
  • if I only want to run this program (called Wintax4), I can do it with 2 ways which are both working well:
- in the dos command window, by entering the command: "C:\Program Files (x86)\MagnetiMarelliracing\Wintax4\WinTAX4.exe"
- using dos function in Matlab: dos("C:\Program Files (x86)\MagnetiMarelliracing\Wintax4\WinTAX4.exe")
  • If I want to run this program with an option which allow to import datas, I'm still able to do it through dos command window, by entering the command (an it works OK):
"C:\Program Files (x86)\MagnetiMarelliracing\Wintax4\WinTAX4.exe" -ImportASCII:"C:\Users\spare\Documents\data.csv";"C:\Users\spare\Documents\param_import.ias"
But when I try with Matlab function "dos" it doesn't work. I've tried:
[status,~]=dos("C:\Program Files (x86)\MagnetiMarelliracing\Wintax4\WinTAX4.exe" -ImportASCII:"C:\Users\spare\Documents\data.csv";"C:\Users\spare\Documents\param_import.ias")
It returns:
[status,~]=dos("C:\Program Files (x86)\MagnetiMarelliracing\Wintax4\WinTAX4.exe" -ImportASCII:"C:\Users\spare\Documents\data.csv";"C:\Users\spare\Documents\param_import.ias")
Error: Invalid expression. When calling a function or indexing a variable, use parentheses.
Otherwise, check for mismatched delimiters.
[status,~]=dos('"C:\Program Files (x86)\MagnetiMarelliracing\Wintax4\WinTAX4.exe" -ImportASCII:"C:\Users\spare\Documents\data.csv";"C:\Users\spare\Documents\param_import.ias"')
I returns -1 to "status" (not "0" => not successfull), and nothing appends.
How can I solve this ?
Many thanks

3 件のコメント

dpb
dpb 2021 年 1 月 18 日
Not having your code we can't test which make it harder to debug.
Probably the short-term way around it would be to put the command into a batch file and dispatch it instead of trying to build a complicated commandline string and pass it.
There's also the problem of which is the working directory when running from the command window vis a vis when spawn a CMD session from MATLAB that can be a gotcha'.
Laurent Fregosi
Laurent Fregosi 2021 年 1 月 21 日
It works OK with a batch file. I don't succeed to find another solution, so I will keep it.
Thank you !
dpb
dpb 2021 年 1 月 21 日
Well, it can be a bear to get embedded blanks/parens nested in passed strings; it will be possible, but you'll just have to sit down at the command line and keep at it until you can build the string to pass and see it on the screen to be complete and accurate.
Doing it in pieces is probably also a help...get one part and then catenate the next...the new string feature with "+" operator might be convenient there, but I haven't tried to see of system() knows about it yet.

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2021 年 1 月 18 日
You cannot use double quotes both to surround the command and inside the command, at least not that way. Something like this would not work. The string ends at the " immediately before Lumos.
%{
S = "She said "Lumos!" and the candle ignited."
%}
You could specify the quote character twice to include it in the string:
S = "You have to pronounce it correctly. ""Wingardium Leviosa!"" The feather rose."
S = "You have to pronounce it correctly. "Wingardium Leviosa!" The feather rose."
Or you may be able to use single quotes inside the string.
S = "Arya's father asked 'What are the words of our house?' She softly replied 'Winter is Coming.'"
S = "Arya's father asked 'What are the words of our house?' She softly replied 'Winter is Coming.'"

カテゴリ

ヘルプ センター および File ExchangeTime Series Events についてさらに検索

製品

リリース

R2020a

タグ

質問済み:

2021 年 1 月 18 日

コメント済み:

dpb
2021 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by