필터 지우기
필터 지우기

Pass parameters to a .exe file and run it.

조회 수: 6 (최근 30일)
Sean Lawson
Sean Lawson 2011년 9월 26일
Hello everyone,
I have a .exe file (which is saved locally) compiled using Visual Studio C#. Now I am writing a software, one of the functions I need is to pass some parameters I got in MATLAB, call and pass these parameters to the .exe file, run .exe file, and save the output locally.
Could anyone please tell how could I do this? Specifically, I am facing the difficulties that I don't know how to use MATLAB to pass parameters to the .exe file and call it to run.
Thank you very much in advance.
Sean
  댓글 수: 1
Sean Lawson
Sean Lawson 2011년 9월 26일
One more thing to mention, all the programs are in Window XP environment.

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

답변 (1개)

Walter Roberson
Walter Roberson 2011년 9월 26일
The function whose name will become the name of the executable: declare it with (varargin) instead of with no parameters.
When you invoke the executable, pass the parameters you want on the command line that invokes the executable. (You might have to frame this differently for C#)
Inside of the main function, you can examine nargin() to find out how many parameters were passed, and you can access them as varargin{1}, varargin{2}, and so on.
Now the important part: each parameter will be received as a string, so if it is intended to represent a number, convert the string to a number before using the value. But avoid using str2num() for doing that, please, as that exposes security holes.
  댓글 수: 1
Sean Lawson
Sean Lawson 2011년 9월 27일
Thank you very much for the help, I will test it after I get the complete .exe file.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by