0

I'm using system() to open and close an external program with which my code communicates. However, every time I use the system() function, I get the console output I would get if I was calling the program from a normal terminal/shell, e.g. every time I call system(killall [program] &) I get a Terminated message. Is there a way to suppress this type of outputs?

joaocandre
  • 1,621
  • 4
  • 25
  • 42

1 Answers1

1

You should use execlp instead of system ;)

https://www.securecoding.cert.org/confluence/display/seccode/ENV04-C.+Do+not+call+system()+if+you+do+not+need+a+command+processor

dotixx
  • 1,490
  • 12
  • 23
  • Problem is, with `execlp` I have I get stuck waiting for the command to finish; What I was looking for was something that would allow me to just start a second process, that runs in parallel with the main program, like I get with `system("[program] &")` – joaocandre Jul 22 '13 at 11:11
  • @joaocandre you should use [std::thread](http://en.cppreference.com/w/cpp/thread/thread). See the accepted answer [here](http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c), put your `execlp` in `task1`. This should do the trick. – dotixx Jul 22 '13 at 11:39
  • Apparently, using `task1.join()` implies waiting for `task1` to finish, so it's not quite what I am looking for. – joaocandre Jul 22 '13 at 16:17
  • @joaocandre just don't call `join()`, the task1 should be executed at the same time without blocking your main thread. – dotixx Jul 22 '13 at 16:52
  • not using `join()` results in `task1` not being lauched at all. I've also tried using `detach` same result. – joaocandre Jul 23 '13 at 10:04