2
launchApplcation调用可以在非Cocoa应用中使用吗? 我需要相当于Windows spawnl(),它从另一个执行应用程序。是否有一个OSX等同于spawn()或exec()?在非Cocoa应用程序中启动应用程序?
我可以使用system()调用,但我需要向它添加命令行参数。
谢谢!
Bill
launchApplcation调用可以在非Cocoa应用中使用吗? 我需要相当于Windows spawnl(),它从另一个执行应用程序。是否有一个OSX等同于spawn()或exec()?在非Cocoa应用程序中启动应用程序?
我可以使用system()调用,但我需要向它添加命令行参数。
谢谢!
Bill
您确实有能力fork和exec其他进程。
例如:
int myPipe[2];
int err, child_pid;
err = pipe(&myPipe); //creates the pipe - data written to myPipe[1] can be read from myPipe[0]
child_pid = fork();
if(child_pid == 0)
{
err = dup2(myPipe[1], 1); //set myprogram's standard output to the input of the pipe
execl("/path/to/myprogram", "arg1", "arg2");
}
int pipefd = myPipe[0];
char buffer[255];
err read(pipefd, buffer, 255); // etc etc
// Ideally you would check that err and child_pid != -1
我不需要用催生程序进行通信。是否需要fork()? – Bill
可能不是,但我不确定(因为我被宠坏了可以访问NSTask和线程等等)。试试execl,看看它是如何发展的。 –
由于某种原因不起作用。我试过:execl(“/ Application/Myprog.app”)和execl(“Macintosh HD/Application/Myprog.app”)任何想法我做错了什么? – Bill