How to call an exe with command line arguments

조회 수: 15 (최근 30일)
hailiang shen
hailiang shen 2011년 4월 1일
댓글: Jan 2017년 4월 9일
Hello All,
I am trying to use system command to call an exe file with command line argument. Please note that this exe file is developed by someone else, and i have no control of it.
I checked the user community, and found one solution to use redirection, but i think that is only applicable if the exe is scanning the user input with functions such as 'scanf' in C/C++.
I am looking for something as: system('a.exe arg1 arg2'). I hope i make my point clear.
Thanks,
Hailiang
  댓글 수: 1
Jason Ross
Jason Ross 2011년 4월 1일
It's unclear if the executable you are talking about accepts command line arguments. If it does, then the system command should work as you indicate. If the executable doesn't accept command line arguments, then there's not much else to do.

댓글을 달려면 로그인하십시오.

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 4월 1일
You can do just like that, right? system('dir') system('dir *.m')
If your argument is a variable, for example, arg2='*.txt', then system('dir arg2') won't work as you expect, you will need to come up with your command string and then run system(), like CommandStr=['dir ',arg2]; system(CommandStr);

hailiang shen
hailiang shen 2011년 4월 3일
Thanks for your suggestions, it works with system('a.exe arg1 arg2') actually. The a.exe can accept command line args.
  댓글 수: 2
Sudharshan Chakravarthy
Sudharshan Chakravarthy 2017년 4월 9일
In this scenario, does arg1 and arg2 need to be numbers (as in system('a.exe 8.5 7.3')) or can they be local variables ?
Jan
Jan 2017년 4월 9일
Here "arg1" and "arg2" must be strings. In
system('a.exe 8.5 7.3')
the executable "a" get the string '8.5' and '7.3' as inputs.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by