Skip to main content

Executing Programs Within Code

Submitted by Kane on
Forum

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 PM Permalink

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 AM Permalink

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

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

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 Kezza on Tue, 17/02/04 - 9:40 AM Permalink

fork is way better

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

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 AM Permalink

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 PM Permalink

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 PM Permalink

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 AM Permalink

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

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

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

Posted by Kane on
Forum

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 PM Permalink

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 AM Permalink

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

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

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 Kezza on Tue, 17/02/04 - 9:40 AM Permalink

fork is way better

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

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 AM Permalink

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 PM Permalink

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 PM Permalink

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 AM Permalink

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

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

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