MATLAB Answers

Finding PID of external process called from MATLAB

55 views (last 30 days)
Sajid Afaque
Sajid Afaque on 24 Dec 2019
Commented: Walter Roberson on 25 Dec 2019
Hello All,
I call an external process(.exe) from matlab on windows machine through the script using 'system()'
is their any way to findout the PID of the above called process (note : the same process may also be active apart from matlab called once i.e several instances of that application may already be active , but i am interested to only find out the PID of the process called from matlab) ?

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Dec 2019
Instead of using system(), use .NET to start the process
After that, the process ID will be the Id property of the object.

  4 Comments

Show 1 older comment
Walter Roberson
Walter Roberson on 24 Dec 2019
proc = System.Diagnostics.Process();
proc.StartInfo.FileName = 'energyPLAN.exe';
proc.StartInfo.Arguments = 'energyPlan Data\Data\Portugal_2050_tmp.txt';
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.Start();
pid = proc.Id();
Sajid Afaque
Sajid Afaque on 24 Dec 2019
i am getting the below error
Message: The system cannot find the file specified
Source: System
HelpLink:
Walter Roberson
Walter Roberson on 25 Dec 2019
This is demo code, like you had asked for. You would need to change FileName to match the path to the exe you want to run, and need to change Arguments to any command line arguments needed.

Sign in to comment.

Tags