commands and arguments problem

This is a discussion on commands and arguments problem within the C Programming forums, part of the General Programming Boards category; Hi, I'm new in Cprogramming and have this problem. I want to run my program like ./my_program command1 [args] command2[args] ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,468
    add delimiters between different commands
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    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

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