Thread: system()-oputput into a variable

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    8

    system()-oputput into a variable

    Hello,

    I execute a system(..) command and this returns a value which I want to save in a variable.

    Code:
    err = system("rsh -l root 172.16.100.144 pidof tcpdump");
    I want to save the PID of tcpdump into a variable to use this PID later in my C programme. Is there a possibility to do this?
    I know an indirect way with redirecting the output into a file and read this file later. But this is no acceptable solution.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Use popen() instead of system().
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    8
    Thank you, it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Calling system with a string variable
    By 911help in forum C Programming
    Replies: 8
    Last Post: 12-27-2007, 08:32 PM
  3. system call variable
    By bradleyd in forum C Programming
    Replies: 5
    Last Post: 05-09-2007, 06:15 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Replies: 2
    Last Post: 02-28-2002, 03:27 PM