Thread: using system() and redirection

  1. #1
    Registered User aryn's Avatar
    Join Date
    Sep 2005
    Posts
    2

    using system() and redirection

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  3. #3
    Registered User aryn's Avatar
    Join Date
    Sep 2005
    Posts
    2
    Thanks I think ive got it working with.
    Code:
    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);
    Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling other binaries, use fork/execl or system?
    By spotvt01 in forum Linux Programming
    Replies: 3
    Last Post: 08-16-2008, 04:20 AM
  2. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 08:04 AM
  3. file existance getting screwy on me...
    By Shadow in forum C Programming
    Replies: 15
    Last Post: 02-16-2002, 01:43 PM