executing a program help

This is a discussion on executing a program help within the C++ Programming forums, part of the General Programming Boards category; I am making a program that can start multiple other programs.
I do this by
_____________________________________
Process ^p;
ProcessStartInfo ^pInfo;
...

That looks like managed C++. (Or managed =~ s/m/d/ as Salem once said. ) I don't know anything about it, but if you can use system(), then read on.

A simple way to run programs in the background without using spawn() or CreateProcess() or some other function from the FAQ is to do this (under Windows):

Code:

system("start program.exe");

start is a program which starts another program in the background. It has several options, such as starting the new program minimized or maximized. The options vary between different versions of Windows -- stick with minimized, maximized, and restored and you should be okay for most Windowses. Open a command prompt and type "start /?" to see the possible options.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

however when i do this the other program takes the place of this one is there a way to stop this from happening

It sounds like the program is doing the equivalent of an exec(), which takes the new program and overwrites the old program with the new. I took it to mean that a program was executing, and took a long time, and the programmer wanted the original program to execute another program while the first one was still going (which is what my reply targeted).

It's possible that system() wouldn't work with that compiler or whatever. I don't know how it works.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

>> I am on g++ Here system() works just with <iostream>
It's generally a bad idea to rely on stuff like that. For example, you might provide sample code to somebody who uses a different compiler, and it doesn't work for them. Or you might change compilers and all of a sudden it dosen't work.

It usually doesn't take that much extra effort to #include the correct header for something you use in your program, and it is usually worth the effort in the end.

This is not a guaranteed behavior, though, if I recall. It just so happens to work on your compiler but may not work on others. The correct library for system() is cstdlib, as stated earlier.

Edit: You might also want to know that if someone were to replace the console executable (cmd.exe on Windows) with a malicious program, calling system() would trigger that malicious program. Thus, system() isn't safe.