简体   繁体   中英

Get output of CMD line program from C++ (specifically netstat)

I want to be able to run "netstat -n" and grab the output somehow so I can then write it out to another file.

How can I do this in C++ on Windows CE

Thankyou

Chris

You must call CreateProcess and override the process's output handle:

STARTUPINFO aInfo;
...
aINfo.hStdOutput = myHandle;
CreateProcess(..., &aInfo, ...);

I solved this by essentially calling netstat from the cmd prompt, piping the output to a file, and then using it from there. I believe Kerido's answer to be right but this is how I got it working.

This code then launches cmd.exe and telling it to run netstat -n. Note that the /c is required else cmd.exe will not launch the code

int retVal = CreateProcessW(L"cmd.exe", L"/c netstat -n > \"/netstatoutput.txt\"", NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, NULL, NULL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM