Thread: commands and arguments problem

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    7

    commands and arguments problem

    Hi,

    I'm new in Cprogramming and have this problem. I want to run my program like ./my_program command1 [args] command2[args] command3 [args]

    for example ./my_program /bin/ps -ef /bin/grep "pattern" /bin/wc -l

    and I need to know in my main function which argument in argv[] array is command and which is argument of this command.

    so in my example /bin/ps, /bin/grep and /bin/wc is commands and -ef, "pattern", -l is their arguments.

    Output of the first command with arguments is input of the second command and output of second command is input of third command.

    Commands arguments are alternative.

    I must compare arguments of main function that beggins with '/'? or is there some better function to detect which argument is extern shell command?

    Thank's all for help.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    add delimiters between different commands
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,835
    Easy enough to check for argv[i][0] == '/'

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Arguments in windows
    By swanley007 in forum C++ Programming
    Replies: 7
    Last Post: 07-28-2006, 09:42 AM
  2. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  3. Problems while reading arguments
    By Lost__Soul in forum C Programming
    Replies: 6
    Last Post: 05-06-2003, 01:02 AM
  4. problem with looping
    By razza in forum C Programming
    Replies: 3
    Last Post: 05-07-2002, 12:39 PM