How to use Process.Start() or equivalent with Mono on a Mac and pass in arguments

后端 未结 4 1832
死守一世寂寞
死守一世寂寞 2020-12-03 02:53

I am trying to write some c# code to start a browser using Process.Start(app,args); where apps is the path to the browser e.g. /Applications/Google Chrome

4条回答
  •  Happy的楠姐
    2020-12-03 03:35

    To make Process.Start use exec directly instead of using the OS' mechanism for opening files, you must set UseShellExecute to false. This is also true on Linux and Windows.

    Process.Start(new ProcessStartInfo (
        "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        "--no-first-run")
        { UseShellExecute = false });
    

    Note that you can also use 'open' for your use case, to run the Chrome app bundle properly. Use the '-a' argument to force it to run a specific app, the '-n' argument to open a new instance, and '--args' to pass in arguments:

    Process.Start(new ProcessStartInfo (
        "open",
        "-a '/Applications/Google Chrome.app' -n --args --no-first-run")
        { UseShellExecute = false });
    

提交回复
热议问题