Jump to content
  • Advertisement
Sign in to follow this  
v3c7r0n

Capture output from the system() function

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm playing with some network stuff right now for a server. its all console right now, and it's also all Win32, so keep that in mind. One of the diagnostics i am working is a tool for pinging the active clients, and in a separate prog just as a test, you can feed it an ip range (which is working) and it will ping it, however what i want to know is if you can somehow capture the output from the ping command so i can display it inside my game. now, since ping runs at the command line i would think there would be a way. ping's output typically looks like this: Pinging <ip address> with 32 bytes of data: <ping time here or time out message> <ping time here or time out message> <ping time here or time out message> <ping time here or time out message> Ping Statistics for <same ip address here>: Packets: Sent = 4, Recieved = (varies based on results), Lost = (again varies) Approximate round trip times in milli-seconds: Minimum = (result), Maximum = (result), Average = (result) All i'm REALLY interested is that last little bit about the ping statistics, because it'd be nice when you're trying to get a game going (LAN or internet) and you can ping everyone from the server. Any help would be apprechiated.

Share this post


Link to post
Share on other sites
Advertisement
The only way you can do it with system() that I can think of is to redirect the shell output to a file and read from that file. A much more elegant way to do that is to spawn a child process connected to the current process with a pipe. I know that in *nix you use popen() but I don't know how to do it on Windows. Maybe something like CreateProcess() or similar can help, but I'm too lazy to look it up myself. [grin]

Share this post


Link to post
Share on other sites
On a win32 system, when a program creates a child process, the child process inherits several attributes from the parent process, including the parent's standard handles. You can use this to create a child process with redirected standard input and output via the SetStdHandle() function.

See also: MSDN.

Share this post


Link to post
Share on other sites
Thanks guys, I figured i'd have to start another process but wasnt really sure. That MSDN link looks like exactly what i need. Maybe one day microsoft will organize their site so one can just say blatently what you want and actually get answers to what you want without getting 2 million specific issue results

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!