views:

106

answers:

2

I'm writing a windows application and I needs to run some console applications from it and get their output. I tried two different approaches:

1) Using _popen(command, "rt") 2) Creating a child process with redirected output (CreateProcess(), CreatePipe())

They both work but during the execution of some command a new console window is created and it's very unpleasant and ugly. Is there some way to execute the commands in background without opening a new console?

+1  A: 

You can use libexecstream.

It allows you to run console programs and read their output using a stream.

As stated by the website it:

  • Works on Linux and Windows
  • Uses threads
  • Does not depend on any other non-standard library
  • Is distributed as source code only, requires you to compile and link one file into your program
  • Has a BSD-style license

I may add that I've successfully used it in a recent project, and that no disgracious console window popped up.

f4
Have you used it to run console applications?
st0n3
yes, I did ----
f4
+2  A: 

You might want to try passing the CREATE_NO_WINDOW or DETACHED_PROCESS flag to CreateProcess.

Anthony Williams
Thanks! I added CREATE_NO_WINDOW and it works.
st0n3