Thread: Obtain path in a variable

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Obtain path in a variable

    Hello,

    I'm programing a C gnu/linux program and I need to execute this command:

    " find /home/javi/ -name "dmtcp_restart" | grep dmtcp/bin/dmtcp_restart"

    when the command has been executed I need to assing the output of the command to a array char variable.

    What linux instructions could be used for obtain this??

    regards

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You have two choices:

    1) The simplest way would be to just use popen() to get the output of the find (not the grep), then parse that for what you are looking for in the grep. However, that is sort of hackish, depends on the existence of "find", and will probably not be as efficient.

    2) The other way is to use readdir() etc. recursively and do the work of "find" yourself. That is a bit more work, unfortunately.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LoadLibrary with variable path
    By DampfHans in forum C++ Programming
    Replies: 7
    Last Post: 11-14-2010, 12:30 PM
  2. Replies: 2
    Last Post: 07-08-2008, 03:45 AM
  3. Obtain Cd-Rom path and one more
    By ch4 in forum Windows Programming
    Replies: 4
    Last Post: 09-14-2007, 04:23 AM
  4. how to obtain the absolute application path
    By jagerhans in forum Linux Programming
    Replies: 4
    Last Post: 12-23-2004, 05:48 PM
  5. filestream- can a path name be a variable
    By stevew2607 in forum C++ Programming
    Replies: 3
    Last Post: 06-07-2002, 04:02 PM