running exe with system

9 visualizzazioni (ultimi 30 giorni)
Edoardo
Edoardo il 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)
fclose(fid);
[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
Edoardo

Risposte (1)

Michelle Hirsch
Michelle Hirsch il 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 ' ...
'OPTION3=%d','myfile.txt',10,20,40);
[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

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by