For a module I'm working on, I've received a compiled Matlab executable (Note it's a stand alone .exe, not a .dll or something along those lines) which I have to execute to do some analysis work for me.
The workflow is that to create an input file (plain simple .csv format), execute the .exe and parse the output file (also .csv) that is generated by the Matlab executable.
I've got the input file generation and output file parsing under test and they work beautifully, if I say so myself. But I'm having some trouble with running the Matlab executable. I have the correct MCR installed and I can double click the executable and it runs just as expected. But using the following code, the executable just doesn't execute properly:
var analyzer = new Process
{
StartInfo =
{
FileName = Path.Combine(WorkDirectory, "analyzer.exe"),
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true // These lines were added for debugging purposes
}
};
analyzer.Start();
punProcess.WaitForExit();
string debuginfo = punProcess.StandardOutput.ReadToEnd();
string debuginfo2 = punProcess.StandardError.ReadToEnd();
The text I pull from "debuginfo" is as follows:
{Warning: Name is nonexistent or not a directory: C:\MATLAB\R2009b\toolbox\pun.}
{> In path at 110
In addpath at 87
In startup at 1}
{Warning: Name is nonexistent or not a directory:
C:\MATLAB\R2009b\toolbox\pun\pun.}
{> In path at 110
In addpath at 87
In startup at 2}
The text I pulled from "debuginfo2" is:
{Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in readin (line 4)
Error in Analyzer (line 12)
}
MATLAB:FileIO:InvalidFid
Are these problems due to my code? Are they due to the context in using it via C#? Or might there be a problem with the analyzer itself? I do not have access to the source of the analyzer executable, so I cannot debug that part.
The error that occurs, could that be because of the warnings given and that I miss some kind of reference (to the MCR maybe?) that is implicitly available when I would just double click it (or run it from cmd, also works like a charm)?
The workdirectory checks out. I've can see the input file being created there by prior C# code, as well as the executable being copied there. So the problem is not due to mistakes in preparing the correct files at the correct locations.
Cheers, Xilconic