Returning info from "system()"

This is a discussion on Returning info from "system()" within the C++ Programming forums, part of the General Programming Boards category; When I use the function "system()", it returns number 0, as it is supposed to. How can I make it ...

  1. #1
    huu
    huu is offline
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    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
    Posts
    3,573
    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
    huu
    huu is offline
    Registered User
    Join Date
    Jan 2009
    Posts
    2
    Du-oh! How blind I was . Thanks.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:12 PM
  4. Binary trees search problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 02-22-2004, 01:29 PM
  5. Replies: 3
    Last Post: 12-06-2001, 04:30 AM

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