我正在尝试编写一些c#代码来启动浏览器,Process.Start(app,args);
其中app是浏览器的路径,例如/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
args--no-default-browser-check
如果我这样做,它适用于Windows和Linux
Process.Start("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","--no-first-run");
Run Code Online (Sandbox Code Playgroud)
我明白了
open: unrecognized option `--no-first-run'
Usage: open [-e] [-t] [-f] [-W] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames]
Help: Open opens files from a shell.
By default, opens each file using the default application for that file.
If the file is in the form of a URL, the file will be opened as a URL.
Options:
-a Opens with the specified application.
-b Opens with the specified application bundle identifier.
-e Opens with TextEdit.
-t Opens with default text editor.
-f Reads input from standard input and opens with TextEdit.
-W, --wait-apps Blocks until the used applications are closed (even if they were already running).
-n, --new Open a new instance of the application even if one is already running.
-g, --background Does not bring the application to the foreground.
-h, --header Searches header file locations for headers matching the given filenames, and opens them.
Run Code Online (Sandbox Code Playgroud)
我也试过Monobjc尝试运行代码
// spin up the objective-c runtime
ObjectiveCRuntime.LoadFramework("Cocoa");
ObjectiveCRuntime.Initialize();
NSAutoreleasePool pool = new NSAutoreleasePool();
// Create our process
NSTask task = new NSTask();
NSPipe standardOut = new NSPipe();
task.StandardOutput = standardOut;
task.LaunchPath = @"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
// add some arguments
NSString argumentString = new NSString("--no-first-run");
NSArray arguments = NSArray.ArrayWithObject(argumentString);
task.Arguments = arguments;
// We should have liftoff
task.Launch();
// Parse the output and display it to the console
NSData output = standardOut.FileHandleForReading.ReadDataToEndOfFile;
NSString outString = new NSString(output,NSStringEncoding.NSUTF8StringEncoding);
Console.WriteLine(outString);
// Dipose our objects, gotta love reference counting
pool.Release();
Run Code Online (Sandbox Code Playgroud)
但是当我使用NUnit运行我的代码时,会导致NUnit爆炸.
我怀疑这是一个错误,但无法证明这一点.我感谢任何和所有的帮助!
Mik*_*son 22
要使Process.Start直接使用exec而不是使用操作系统的机制来打开文件,必须将UseShellExecute设置为false.在Linux和Windows上也是如此.
Process.Start(new ProcessStartInfo (
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"--no-first-run")
{ UseShellExecute = false });
Run Code Online (Sandbox Code Playgroud)
请注意,您还可以对用例使用"打开",以便正确运行Chrome应用包.使用'-a'参数强制它运行特定的应用程序,' - n'参数打开一个新实例,' - args'传递参数:
Process.Start(new ProcessStartInfo (
"open",
"-a '/Applications/Google Chrome.app' -n --args --no-first-run")
{ UseShellExecute = false });
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23536 次 |
最近记录: |