0

I'm starting a process by using Process class in unity.

Process myProcess = new Process();
        myProcess.StartInfo.FileName = path;
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
        myProcess.StartInfo.Arguments = JsonConvert.SerializeObject(params);
        myProcess.Start();

I'm using unity for OSx. I tested it by creating a new console application sending the same string arguments and using the same path, and it actually works fine. When I try to start the process from unity it just does not work and does not send any error even the code below the process call works, so I think it succeed but nothing happens. I can't get why. By the way I start the process call in a unity button event.

MisaelGaray
  • 75
  • 2
  • 10
  • Have you ever view the value of `JsonConvert.SerializeObject(params);` in both console and unity? Maybe the values are different? – Programmer Mar 29 '17 at 19:22
  • Both are the same json object, I even try without sending arguments in both and the application run (In the test console application) and send an error because I'm not passing data, but in unity the console is not launched. – MisaelGaray Mar 29 '17 at 19:53
  • Have you tried some of the suggestions [here](http://stackoverflow.com/questions/15452651/start-an-external-process-on-mac-with-c-sharp) and [here](http://answers.unity3d.com/questions/161444/how-to-use-processstart-with-arguments-on-osx-in-a.html)? – Foggzie Mar 29 '17 at 22:09
  • Yes I tried all of them yet, but nothing happens, the application does not run. – MisaelGaray Mar 30 '17 at 16:47

1 Answers1

0

I used this method to call external process in Unity.

public static void ExecProcess(string name, string args)
{
    Process p = new Process();
    p.StartInfo.FileName = name;
    p.StartInfo.Arguments = args;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.UseShellExecute = false;
    p.Start();

    string log = p.StandardOutput.ReadToEnd();
    string errorLog = p.StandardError.ReadToEnd();

    p.WaitForExit();
    p.Close();
}

For async version you'll need light modification.

  • A Tried it but I got this error `Win32Exception: ApplicationName='/Applications/Bamboo Wall Binary/WeightsResults.exe', CommandLine='', CurrentDirectory='' System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) System.Diagnostics.Process.Start () (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()` sorry for pasting the whole error – MisaelGaray Mar 30 '17 at 17:00
  • @MisaelGaray why there is WeightsResults.exe? You are using OSX. It doesn't run exe files. – Vladyslav Melnychenko Mar 30 '17 at 17:36