能否在非 Cocoa 应用程序中使用 launchApplcation 调用? 我需要 Windows spawnl() 的等价物,它从另一个应用程序中执行一个应用程序。是否有等同于 spawn() 或 exec() 的 OSX?
我可以使用 system() 调用,但我需要向它添加命令行参数。
谢谢!
比尔
最佳答案
您确实有能力 fork 和执行其他进程。
例如:
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
关于c++ - 在非 Cocoa 应用程序中启动应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8086949/