running exe with system
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Michelle Hirsch
2011년 2월 8일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!