我有一个这样的程序
program1.exe program2.exe
我需要让它像这样运行
%USERPROFILE%program1.exe program2.exe
如何在C上做到这一点?
据我所知,你使用的是Microsoft Windows。
你的问题有(至少)两个答案,一个简单,一个与Windows操作系统接口有关,通常称为Win32 API。
我们用简单的那个。如果您希望对第二个程序的执行有更多的控制,请评论。
#include <stdio.h> /* printf() */
#include <stdlib.h> /* system() */
int main(int argc, char* const* argv)
{
int rv;
if (argc < 2) {
printf("Please inform the name of the program to execute.n");
return 1;
}
rv = system(argv[1]);
printf("Program execution returned %dn", rv);
return 0;
}