Thread: Returning info from "system()"

  1. #1
    Registered User
    Join Date
    Jan 2009

    Returning info from "system()"

    When I use the function "system()", it returns number 0, as it is supposed to.
    How can I make it to return a string? For example, I want it to return the PID of some process, using the Linux shell command "pidof".

  2. #2
    The larch
    Join Date
    May 2006
    system returns the return value of the program that was called, so it can only be an integer.

    I guess you can redirect output of "pidof" (e.g to a file and then read it from there).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jan 2009
    Du-oh! How blind I was . Thanks.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Or use popen() / pclose(), which saves all the messy temporary file business.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help displaying info from structure
    By kisiellll in forum C Programming
    Replies: 6
    Last Post: 04-04-2009, 12:51 PM
  2. Question about getting an info class from another Form
    By Joelito in forum C# Programming
    Replies: 0
    Last Post: 10-16-2006, 01:02 PM
  3. Help doing an e-mail program in c...
    By Tyler_Durden in forum C Programming
    Replies: 88
    Last Post: 01-02-2005, 03:12 PM
  4. Binary trees search problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 02-22-2004, 02:29 PM
  5. Replies: 3
    Last Post: 12-06-2001, 05:30 AM