views:

201

answers:

3

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

A: 

http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx

But not pretty sure it'll work under CE

drlazy
+3  A: 

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

STARTUPINFO aInfo;
...
aINfo.hStdOutput = myHandle;
CreateProcess(..., &aInfo, ...);
Kerido
Hey thanks... can you embellish a little on this?
Chris
Specifically what do I set myHandle to so I can access it later as a string?
Chris
A: 

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);
Chris
I can not run this code. When i print GetLastError i get error 87.Can you explain?
shake