1

I'm using create process win32 function to start windows shell application for example Ipconfig and get its output but without popup cmd windows .
Also I trying with the POCO library and its process class but each time the cmd popup.

does any body knows how to do it with the POCO lib there is not mush support in the POCO forums ?

1
  • This is actually rather difficult. Without a console, a Windows program does not have stdin and stdout streams.
    – user2100815
    May 24, 2011 at 8:37

3 Answers 3

3

To hide thw window, try passing SH_HIDE when calling CreateProcess on lpStartupInfo.

STARTUPINFO si = {0};
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;    
CreateProcess(/*...*/, &si /*...*/);

If you want to collect the results, you can call CreateFile to obtain a file handle, and pass the handle in STARTUPINFO structure, then read it when CreateProcess returns:

STARTUPINFO si = {0};
si.cb = sizeof(si);
si.hStdOutput = hOutput;
si.hStdError = (HANDLE) STD_ERROR_HANDLE;
si.hStdInput = (HANDLE) STD_INPUT_HANDLE;
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
CreateProcess(/*...*/, &si /*...*/);
0
3

You can create a CMD process without a window but you need to set the right flags for this when you create your process you also need to redirect output.

If you need to get at the ipconfig stuff I'd recommen just going through the IP Helper functions of the Win32 API instead.

1

At least in windows, there are some asterisks around pulling standard output from anything that runs in a command prompt. If you've ever looked into writing a replacement for the windows command prompt you would know. Only way I know of to get precise output is to grab characters directly out of the command prompt. There is an example of this in open source project Console http://sourceforge.net/projects/console/

In some circumstances changing the file handle of standard output to something you can read from will work however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.