![](/img/trans.png)
[英]Is there an equivalent of Mac OS X “open” command that can be called from C++/Objective-C code?
[英]C header for Mac OS X open Command or equivalent
我已經讀過這些:
我正在嘗試從打開命令中獲取PID。 我們有一個內部的多平台C ++庫,例如(過於簡化):
pid = launch(char* command)
// Many other parameters and variations (sync/async,timeout,stdout,stderr,stdin )
但是,在OS X上,庫用戶通常使用以下命令:
Open myExe myArgs -F
它似乎:
我非常歡迎任何解決方案:
回到寫我的解決方法的答案,我不喜歡它,因為我確實需要使用一些可可粉,但是它可以工作...
我已經獲得了所需的“前景”行為,並使用以下代碼獲得了Pid:
NSString * arg1 = @"--my_arg";
NSString * arg2 = @"arg_value";
NSArray * myArray2 = [NSArray arrayWithObjects:arg1,arg2,nil];
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setObject:myArray2 forKey:NSWorkspaceLaunchConfigurationArguments];
bURL = [NSURL fileURLWithPath:@"/path/to/appli.app"];
NSRunningApplication * inst = [ws launchApplicationAtURL:bURL options:NSWorkspaceLaunchNewInstance configuration:dict error:nil];
pid_t pid = [inst processIdentifier];
在Xcode中,可以在我的file.mm中使用上面的代碼,其簽名在我的file.h中聲明。 Xcode將自動管理可可粉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.