开发者

Command line commands with C

I'm sorry if this was co开发者_开发问答vered before, but I can't find it anywhere on StackOverflow.

Basically I'm trying to run things that you usually run at a Windows command prompt:

msiexec /i file.msi /q

and other sort of commands from my C program. Is this possible?

Thanks.


In windows using the Win API ShellExecute will give you best control of your child process. However the other two methods mentioned by Dave18 and Pablo work as well.


Try C system function

#include <stdlib.h>

int main ()
{

  system ("msiexec /i file.msi /q");
  return 0;
}


You need to use one of the functions from the exec family of function. Here's a list of them.

So, to run your example you can use:

execl("msiexec","/i","file.msi","/q",NULL);


Pablo and Dave are right, depending on what you want to do.

execl loads the new application into memory and runs it in place of the current process. Your program will end after the execl() call.

System runs the application in a subshell, you can retrieve it's exit status but not any information about it's stdin/stdout data.

How interested are you in what happens after you start the process?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜