views:

293

answers:

1

I'm trying to make an external system call using mono. I'd like to know if it's possible to emulate something like the example below (Of course I'm looking for cross platform support).

public static int ExecuteExternalApp()
            {
                int ExitCode = -1;
                Process Process = new Process(); ;

                //Defining the filename of the app
                Process.StartInfo.FileName = "java";

                //Assigning the args to the filename
                Process.StartInfo.Arguments = @"-jar """ + ConfigurationManager.AppSettings["JarPath"].ToString();

                try
                {
                    //Starting the process
                    Process.Start();

                    //Waiting for the process to exit
                    Process.WaitForExit();

                    //Grabbing the exit code
                    ExitCode = Process.ExitCode;

                    //Close the process
                    Process.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }

                return ExitCode;
            }

**UPDATE: This code does work in mono. The first implementation did not work because of a non-existent reference to the System namespace (no idea of how that happened), this code block works as long as the System.Diagnostics namespace is used.

+2  A: 

I'm not sure if this is what you wanted, but look at the code sample I've posted in http://stackoverflow.com/questions/687594/windows-service-application-controller/687607#687607, this works in Mono.

Igor Brejc
I couldn't find the System.Diagnostics namespace among the provided packages to do it in the first place. How did you reference it?
Raúl Roa
To tell you the truth I don't know: the code I posted works using Mono, but I've compiled it in VisualStudio+.NET.
Igor Brejc
Looking at Mono's docs (http://www.go-mono.com/docs/index.aspx?link=N%3ASystem.Diagnostics), there shouldn't be a problem referencing System.Diagnostics
Igor Brejc
You are right it just worked, apparently my compiler went crazy or I didn't have a Reference to System in the first place when I tried to use it. Thanks.
Raúl Roa
Even my actual code works
Raúl Roa