How can i assign the ouput from system("ping myIP") to a variable on the linux platform. Im actually using a program called ding which prints an integer to the consoe. I need to redirect the output from the console to the variable.
This is a discussion on using system() and redirection within the C++ Programming forums, part of the General Programming Boards category; How can i assign the ouput from system("ping myIP") to a variable on the linux platform. Im actually using a ...
How can i assign the ouput from system("ping myIP") to a variable on the linux platform. Im actually using a program called ding which prints an integer to the consoe. I need to redirect the output from the console to the variable.
popen() is probably the easiest thing to use
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
Thanks I think ive got it working with.
Thanks againCode:FILE *fp; char line[10]; fp = popen("ding -s -r 202.......", "r"); while ( fgets( line, sizeof line, fp)) { cout << "result is " << line << endl; } pclose(fp);