I have a function in Matlab and I want to call it from the command prompt which is started from C# program, and get the result code
Matlab function
function func(v1,v2)
v1
v2
end
I call it with
matlab -wait -r "func('hello','goodbye');"
The function executes normally and finishes but the command prompt is still waiting and when the matlab program close the command prompt becoming free but I want to get the exit code
Actually I start this command prompt from a C# program and I want to understand if the function is successfully executed or not. when I close the cmd manually I get the error in C# program however the matlab function is done successfully. I want to get the related exit code in C# program
My C# code is like:
strMatlabCommand = "/K matlab -wait -sd \"D:\\directory\" -r \"func('" + variable1 + "','"+ variable2 + "' )\" ;";
mcdProcess = new System.Diagnostics.Process();
mcdProcess.StartInfo.FileName = "cmd.exe";
mcdProcess.StartInfo.Arguments = strMatlabCommand;
mcdProcess.Start();
mcdProcess.WaitForExit();
this.Text = mcdProcess.ExitCode.ToString();
if (mcdProcess.ExitCode == 0)
{
MessageBox.Show("Process Finished Successfully", "Result", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("Process Finished Unsuccessfully!!!!", "Result", MessageBoxButtons.OK);
}
any help would be appreciated