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?
Asked
Active
Viewed 1,542 times
0

joaocandre
- 1,621
- 4
- 25
- 42
-
3Redirect their output to `/dev/null`, as always. – Jon Jul 10 '13 at 20:40
-
@Jon I'm already trying that, but I still get "Terminated" messages on the console. – joaocandre Jul 22 '13 at 10:24
1 Answers
1
-
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