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

3 views (last 30 days)
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 Comments
Laurent Fregosi
Laurent Fregosi on 21 Jan 2021
It works OK with a batch file. I don't succeed to find another solution, so I will keep it.
Thank you !
dpb
dpb on 21 Jan 2021
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.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 18 Jan 2021
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.'"

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!