System()

closed account (LzqpfSEw)
What library (g++) is system() included in?

How can I also get System to return whatever it was doing.

E.G

system("ping google.com");

I want it to return to me the ping time.

Thx.
The second question is a little bit tougher than you probably anticipate- generally when I need the data output to a program's console (AKA stdout && stderr) I will use createProcess to open the program. However this only works in windows- and if you're using g++ i'm assuming your on a linux platform?
closed account (LzqpfSEw)
Yes I'm running Xubuntu 10.10
Aha- well I have no experience in linux stream redirects- however I can point you in the right direction.

Your best bet is to create a child process still probably.
You can use pipes, I believe.

Some possible references:
http://linux.die.net/man/2/fork
http://linux.die.net/man/2/pipe
http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/redirecting-standard-io.html
closed account (LzqpfSEw)
A lot of this is beyond my understanding, I'll have to go further into C++ before attempting this again I think.
It's not particularly hard. Something along the lines of:
1
2
3
4
5
6
FILE* fildes=popen("ping www.google.com","r");
if (fildes)
{
  //here you can read the data using C functions such as fgets
  pclose(fildes);
}
Topic archived. No new replies allowed.