1

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

1
  • 1
    Try setting ProcessStartInfo.WorkingDirectory to the .exe location. Commented Aug 21, 2012 at 14:54

1 Answer 1

2

As Dmitriy Reznik commented, specifying the WorkingDirectory of the StartInfo solved the problem I was having. Is should look like this:

var analyzer = new Process
{
    StartInfo =
    {
        FileName = Path.Combine(WorkDirectory, "analyzer.exe"),
        WorkingDirectory = WorkDirectory
        CreateNoWindow = false,
        WindowStyle = ProcessWindowStyle.Hidden,
        UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true // These lines were added for debugging purposes
    }
};
analyzer.Start();
punProcess.WaitForExit();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.