x


How can I start a process to open Finder to point to a file?

I'm working on a standalone for OSX and Windows that will output some data to a text file, and I'd like for Unity to open the native file browser to point to that file when it's finished (so users can email me the file, etc.). So far I have the following:

void OnDataParsed (string path)
{
#if UNITY_STANDALONE_OSX || UNITY_EDITOR
    try
    {
        Process process = new Process ();
        process.StartInfo.FileName = "open";
        process.StartInfo.Arguments = "-n -R " + path.Replace (" ", "\\ ");
        UnityEngine.Debug.Log (process.StartInfo.FileName);
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.RedirectStandardOutput = true;
        process.ErrorDataReceived += OnFinderError;
        if (process.Start ())
        {
            UnityEngine.Debug.Log ("Started properly");
            process.BeginErrorReadLine ();
            process.BeginOutputReadLine ();
        }
        else
        {
            UnityEngine.Debug.Log ("Error");
        }
    }
    catch (System.Exception e)
    {
        UnityEngine.Debug.Log (e.Message);
    }
#endif
}

void OnFinderError (object sender, DataReceivedEventArgs args)
{
    UnityEngine.Debug.Log (args.Data);
}

Which, on running in the editor, prints "Started properly" but no finder window shows up. I see the same result regardless of whether "UseShellExecute" is true or false (I set it to false before I copy/pasted to redirect output). Any ideas on what I might be doing wrong?

more ▼

asked Dec 02 '11 at 08:13 PM

burnumd gravatar image

burnumd
3.3k 22 34 71

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

This problem appears to be a known issue with the version of Mono used by Unity (and it's currently listed as resolved). See here and here. Escaped spaces are ignored in arguments. The workaround is to put the entire path inside quotes.

more ▼

answered Dec 09 '11 at 04:21 PM

burnumd gravatar image

burnumd
3.3k 22 34 71

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x242
x24
x8
x3

asked: Dec 02 '11 at 08:13 PM

Seen: 633 times

Last Updated: Dec 09 '11 at 04:21 PM