3

my application is not a console application. I am using _popen to run a command line command from my code. a console windows appears while the _popen process is running. I want to hide this windows.

  • possible duplicate of [Is there any way of stopping \_popen opening a dos window?](http://stackoverflow.com/questions/10020653/is-there-any-way-of-stopping-popen-opening-a-dos-window) – Axalo Feb 24 '15 at 04:46

2 Answers2

2

Use ShellExecute() instead of _popen() or system().

https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx

more details: https://msdn.microsoft.com/en-us/library/windows/desktop/bb776886(v=vs.85).aspx

JohnH
  • 2,653
  • 10
  • 21
  • 1
    Use [`ShellExecuteEx`](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762154%28v=vs.85%29.aspx) instead if you need the process exit code. That works to replace `system`. But it's only a partial replacement for `_popen` since it doesn't enable piping data in or out of the child process. – Eryk Sun Feb 24 '15 at 06:27
1

You can use WinExec("your cmd command", SW_HIDE); instead of system or _popen

  • 5
    [`WinExec`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms687393%28v=vs.85%29.aspx) is a poor replacement for `_popen`, or even `system`. It doesn't return a process handle on which to wait and call `GetExitCodeProcess`, and it doesn't let you write to stdin or read from stdout. It was deprecated from the first release of Win32, and only provided for backward compatibility with 1980s Win16 programs. – Eryk Sun Feb 24 '15 at 06:23