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 _pop开发者_运维问答en(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?
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.
You might want to try passing the CREATE_NO_WINDOW
or DETACHED_PROCESS
flag to CreateProcess
.
精彩评论