开发者

Execute console applications without creating a new console window flickering on the screen (C++, Windows)

开发者 https://www.devze.com 2023-01-07 21:43 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号