编写一个程序在c上运行其他程序

  • 本文关键字:程序 运行 其他 一个 c
  • 更新时间 :
  • 英文 :


我有一个这样的程序

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;
}

最新更新