Cannot start the process

rrradorrrado Member ✭✭
edited July 2018 in Xamarin.iOS

My Xamarin.mac cocoa application includes native console application in the bundle and at some point it starts the console application with redirected standard input and output like this:

    ProcessStartInfo pi = new ProcessStartInfo(apiProcessPath);
                    pi.WorkingDirectory = workingDirectory;
                    pi.Arguments = "0";
                    pi.UseShellExecute = false;
                    pi.CreateNoWindow = true;
                    pi.RedirectStandardOutput = true;
                    pi.RedirectStandardError = true;
                    pi.RedirectStandardInput = true;

                    Process process = Process.Start(pi); 

It works on my computer (Mac OS High Sierra - my application installed in the /Applications/...) but at customer's computer with the same OS installed also at the same folder the Process.Start throws this exception:

System.IO.IOException: Write fault on path /Applications/my app folder/Contents/Resources/[Unknown]
at System.IO.FileStream.WriteInternal (System.Byte[] src, System.Int32 offset, System.Int32 count) [0x000be] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/corlib/System.IO/FileStream.cs:658
at System.IO.FileStream.Write (System.Byte[] array, System.Int32 offset, System.Int32 count) [0x00090] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/corlib/System.IO/FileStream.cs:614
at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) [0x00042] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/io/streamwriter.cs:312
at System.IO.StreamWriter.set_AutoFlush (System.Boolean value) [0x00010] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/io/streamwriter.cs:336
at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x0033e] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/System/System.Diagnostics/Process.cs:796
at System.Diagnostics.Process.Start () [0x0003a] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2005
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x0001b] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.4.1.176/src/Xamarin.Mac/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2476

Application was compiled with Visual Studio 7.5. I've also tried to update to 7.5.4, but result was the same (except release build seems to be less detailed in this case so I've posted original call stack).
I don't have access to that computer so I cannot debug it. It seems the /var/log/system.log shows nothing related to my application. Do you have idea what could be wrong? I've also created new testing application from scratch invoking just "/bin/cat" the same way but it worked.
All similar I could find was one unsolved SO question but it seems I cannot post the link. I'm not sure if i could post it as bug since it behaves differently on two computers, but unfortunately I cannot reproduce it so I ask here first. Thank you.

Answers

  • YuriKuznetsovYuriKuznetsov USMember ✭✭✭

    You can use NSTask instead of ProcessStartInfo

        //string[] args = new string[] { "-p", " sp" };
            string[] args = consoleParams;
    
            NSTask task = new NSTask();
    
            //path to app
            //task.LaunchPath = "/Applications/MyApp.app/Contents/MacOS/MyApp";
            task.LaunchPath = pathToApp;
    
            task.Arguments = args;
    
            NSPipe pipe = new NSPipe();
            task.StandardOutput = pipe;
            task.Launch();
    
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Also see https://github.com/xamarin/xamarin-macios/blob/master/tools/common/Driver.cs#L231

    We use Process.Start there, and it's pretty bullet proof after years of bug fixing.

  • rrradorrrado Member ✭✭

    Thank you guys, I've found the problem. It is caused by missing dynamic library which is not installed on other computer. Unfortunately the exception I'm getting is very misleading.

  • rrradorrrado Member ✭✭

    @YuriKuznetsov said:
    You can use NSTask instead of ProcessStartInfo

    //string[] args = new string[] { "-p", " sp" };
    string[] args = consoleParams;

            NSTask task = new NSTask();
    
            //path to app
            //task.LaunchPath = "/Applications/MyApp.app/Contents/MacOS/MyApp";
            task.LaunchPath = pathToApp;
    
            task.Arguments = args;
    
            NSPipe pipe = new NSPipe();
            task.StandardOutput = pipe;
            task.Launch();
    

    Thank you for idea, it helped to confirm the problem. When I start process this way, I can see the error message about missing dylib in the standard error.

  • rrradorrrado Member ✭✭

    @ChrisHamons said:
    Also see github.com/xamarin/xamarin-macios/blob/master/tools/common/Driver.cs#L231

    We use Process.Start there, and it's pretty bullet proof after years of bug fixing.

    Difference in your code is that there is no StandartInput redirection, but the exception is thrown in the framework's code which is dealing with redirected standard input so you would not get that kind of exception. Than you.

Sign In or Register to comment.