C Command Line Commands

I apologize if this has been considered before, but I cannot find it anywhere in StackOverflow.

Basically, I'm trying to run the things that you usually run on the Windows command line:

msiexec / i file.msi / q

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

Thank.

+5
source share
4 answers

In windows using the Win API, ShellExecute will give you better control over your child process. However, the other two methods mentioned by Dave18 and Pablo also work.

+3
source

Try the C system function

#include <stdlib.h>

int main ()
{

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

exec. .

, :

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

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

execlloads a new application into memory and launches it instead of the current process. Your program will terminate after a call execl().

The system starts the application in a subshell, you can get its exit status, but not information about it, data stdin / stdout.

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

+1
source

All Articles