Skip to main content

Executing Programs Within Code

Submitted by Kane on

I want to write a program that runs different programs depending on user input. How on earth do I do this?

Using C++ by the way...

Submitted by TheBigJ on Mon, 16/02/04 - 9:48 PMPermalink

The easiest way in windows is probably the system() function:

int system(const char *command);

The command string is the command to run, for example:

system("C:FooMyProgram.exe");

Submitted by Kane on Tue, 17/02/04 - 3:05 AMPermalink

sick...do I have to #include anything special?

Submitted by redwyre on Tue, 17/02/04 - 9:23 AMPermalink

Noooooo! That should be ! isn't even standard! Bad Big J! *slaps wrist*

If you want more control (and are planning to only run in windows) ShellExecute[Ex] is an alternative.

Submitted by Blitz on Tue, 17/02/04 - 11:00 AMPermalink

fork isn't available in windows. I think the (somewhat) equivalent is _spawn() ??
CYer, Blitz

Submitted by Daemin on Tue, 17/02/04 - 11:29 AMPermalink

fork only creates another process anyway, you'd manually also have to load the executable code into that process and get it running. Using the system call or the windows only ShellExecute is preferred and much simpler.

Submitted by TheBigJ on Tue, 17/02/04 - 10:31 PMPermalink

Hmm.. Not so sure about fork..

And Yes, sorry about . Was going from memory, haven't used system() for a while. I would normally use ShellExecute[Ex].

Submitted by redwyre on Wed, 18/02/04 - 9:59 PMPermalink

Well, you know what they say... "When all you have is a fork, everything looks like a process..." or something...

Submitted by davidcoen on Fri, 20/02/04 - 5:30 AMPermalink

mem wars flash back, take both branches (and fork)

Submitted by ReDucTor on Sun, 07/03/04 - 10:21 PMPermalink

I prefer to use CreateProcess() gives you more control when starting it.

Posted by Kane on

I want to write a program that runs different programs depending on user input. How on earth do I do this?

Using C++ by the way...


Submitted by TheBigJ on Mon, 16/02/04 - 9:48 PMPermalink

The easiest way in windows is probably the system() function:

int system(const char *command);

The command string is the command to run, for example:

system("C:FooMyProgram.exe");

Submitted by Kane on Tue, 17/02/04 - 3:05 AMPermalink

sick...do I have to #include anything special?

Submitted by redwyre on Tue, 17/02/04 - 9:23 AMPermalink

Noooooo! That should be ! isn't even standard! Bad Big J! *slaps wrist*

If you want more control (and are planning to only run in windows) ShellExecute[Ex] is an alternative.

Submitted by Blitz on Tue, 17/02/04 - 11:00 AMPermalink

fork isn't available in windows. I think the (somewhat) equivalent is _spawn() ??
CYer, Blitz

Submitted by Daemin on Tue, 17/02/04 - 11:29 AMPermalink

fork only creates another process anyway, you'd manually also have to load the executable code into that process and get it running. Using the system call or the windows only ShellExecute is preferred and much simpler.

Submitted by TheBigJ on Tue, 17/02/04 - 10:31 PMPermalink

Hmm.. Not so sure about fork..

And Yes, sorry about . Was going from memory, haven't used system() for a while. I would normally use ShellExecute[Ex].

Submitted by redwyre on Wed, 18/02/04 - 9:59 PMPermalink

Well, you know what they say... "When all you have is a fork, everything looks like a process..." or something...

Submitted by davidcoen on Fri, 20/02/04 - 5:30 AMPermalink

mem wars flash back, take both branches (and fork)

Submitted by ReDucTor on Sun, 07/03/04 - 10:21 PMPermalink

I prefer to use CreateProcess() gives you more control when starting it.