0

I have written a program using C++, which I call

system("C:\xampp\xampp-control.exe");
to run the xampp control panel. When I run the program after compiling, it runs smoothly, except the program I have written is still running. Once the XAMPP control panel is launched, I want to terminate the program. What could possibly be done? Any help is much much appreciated.
Romeo Sierra
  • 1,666
  • 1
  • 17
  • 35
  • 1
    The best scenario would be to not use `system()` to launch it. Instead, launch the new process using any system call that does it without blocking, and then simply `exit()` your program. – mah May 22 '15 at 15:04
  • Maybe you can use `exit (int status);` if i understand your problem correctly. – Javia1492 May 22 '15 at 15:04
  • Wrong tool for the job: [system documentation](http://linux.die.net/man/3/system) and relevant quote *"and returns after the command has been completed"*. – crashmstr May 22 '15 at 15:19

1 Answers1

2

You can replace your application by the one being called with exec.

// Note: this waits for the exectued program to finish
// before the call to `system()` returns.
system("C:\xampp\xampp-control.exe");

// You can replace the current processes with the one you
// are starting like this.
execl("C:\xampp\xampp-control.exe", "xampp-control.exe");
// If this returns the applicaion failed to start.
std::cerr << "Failed to start application\n";
exit(1);
Martin York
  • 257,169
  • 86
  • 333
  • 562
  • Thank you very much... Found a better alternative with `ShellExecute()`.. :) – Romeo Sierra May 22 '15 at 15:31
  • Could you elaborate why it is not a better solution? :) Please don't take it as if I am teasing. I am a newbie to C++. So I am curious to know how things work around here... – Romeo Sierra May 22 '15 at 16:26