有个API函数可以直接调用 ShellExecute(NULL,NULL,"D:\\test.ext",NULL,NULL,NULL);
其中第3个参数就是 exe程序的绝对路径.
yourexe.exe /d 假设你命令行接受这样的选项比如/d
system("yourexe.exe /d");
被调用的程序如果需要有输入参数,可以通过位置参数方式给入。
例如:a.c 需要输入1个int参数
#include
#include
main(int argc,char *argv[]){
int d;
if (argc>=2) {
sscanf(argv[1],"%d",&d);
printf("value d=%d\n",d );
}
else printf("pass\n");
}
程序 b.c 将调用 a.exe 3 次:
#include
#include
#include
main(){
char cmd[80];
int x[]={456,789,321};
int i;
for (i=0;i<3;i++)
{
sprintf(cmd,"Start /WAIT /B a.exe %d",x[i]);
system(cmd);
Sleep(2000); //隔2秒钟
}
printf("finished\n");
}
执行结果:
value d=456
value d=789
value d=321
finished
用
#include
#include
int main()
{
system("echo 2 > tmp");
system("echo 1 >> tmp");
system("echo 0 >> tmp");
system("yourexe.exe < tmp");
remove("tmp");
}
来,楼主试试我这个代码。 yourexe自己改,知道吧