running exe with system

14 views (last 30 days)
Edoardo on 8 Feb 2011
Hi everybody,
I'm trying to run an .exe with the matlab system command.
The command line for this script (when I run it under dos, for instance) is
cpgi130.exe FILE.input OPTION1=10 OPTION2=20 OPTION3=40
What I want to do is running this command line into a for cycle with different input files for each step
I tried the following as explained in a previous post:
mycomm = ['ChromosomeEL_33.fasta LENGTH=500 GC==55'];
fid = fopen(fname, 'wt');
fprintf(fid, mycomm)
[status, result] = system(['cpgi130.exe ' fname]);
It works only partially because I can input the system with the correct file but not the specified options. I know one should use the '<' to tell to system which option the .exe uses.
But how do I tell to system both the input file name AND the options?
Many thanks

Answers (1)

Michelle Hirsch
Michelle Hirsch on 8 Feb 2011
I'm a little confused about your question. I would expect that you want to build a string that looks exactly like the one you would use at the DOS command line. Assuming that your challenge is just building this string, there are a couple of approaches.
You could keep concatenating the different options, e.g.
[status, result] = system(['cpgi130.exe ' fname 'OPTION1=' num2str(500) ' GC=' num2str(55)]);
Though I would recommend that you try using sprintf to construct the command to pass to system instead of using []:
str = sprintf('cpgi130.exe %s OPTION1=%d OPTION2=%d ' ...
[status, result] = system(str);
The %s and %d mark places where you want to insert values into the string. Each one adds another input argument to the end of the call to sprintf in order, so the %s maps to the filename and the three %d's map to the option numbers. s=string, d=number.
Is this what you are looking for?
- scott


Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!