using getopt() more than once

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Praveen

    #1

    using getopt() more than once

    Hi,

    Any one ever used getopt function more than once. Here is my example.
    I have to run a process as

    myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile"

    First I have to check for -c option and use the value of this -x
    argument for next get opt.

    Any one has an experience in the same. The reply will be highly
    appreciated.

    Regards
    Praveen Kumar M

  • Malcolm

    #2
    Re: using getopt() more than once


    "Praveen" <praveenmadis@g mail.com> wrote[color=blue]
    > Any one ever used getopt function more than once. Here is my example.
    > I have to run a process as
    >
    > myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile"
    >[/color]
    The thing to do in these situations is first, read the documentation for the
    function, and second do a bit of exploratory programming. Just get the
    options and echo them to stdout.
    getopt() is not an ANSI function and it is years since I last used it, so I
    couldn't tell you exactly how it works.


    Comment

    • Giovanni

      #3
      Re: using getopt() more than once

      Praveen wrote:[color=blue]
      > Hi,
      >
      > Any one ever used getopt function more than once. Here is my example.
      > I have to run a process as
      >
      > myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile"
      >
      > First I have to check for -c option and use the value of this -x
      > argument for next get opt.
      >
      > Any one has an experience in the same. The reply will be highly
      > appreciated.
      >
      > Regards
      > Praveen Kumar M
      >[/color]

      I don't really understand what you mean. But in the manner you wrote it
      and assuming that -c is specified with an argument ("c:" in the option
      string) the string "-a -f myFile -o myOutput -d debugFile" is parsed as
      a single argument to -c. Otherwise will be parsed as a positional argument.

      I don't think you can parse it using getopt() since it is a single
      string not an array of pointers to the single word.

      Ciao
      Giovanni
      --
      A computer is like an air conditioner,
      it stops working when you open Windows.
      Registered Linux user #337974 <http://counter.li.org/>

      Comment

      Working...