我想在我的代码中使用的程序是一个命令行工具。
用户./program
首先键入,然后用户可以使用程序提供的一些命令。
我想在我的源代码(myCode.cpp
)中执行两个命令:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
printf ("Checking if processor is available...");
if (system(NULL)) puts ("Ok");
else exit (EXIT_FAILURE);
printf ("Executing command ...\n");
system ("./program");
system ("command1");
system ("command2");
return 0;
}
执行我的程序(./myCode
)后,程序启动,但没有执行这两个命令。
如何执行这两个命令?
如何终止程序然后执行我的以下代码行?(之后system()
)