using system() and redirection

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 ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    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.

  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, 05: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, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21