Re: Dealing with fragmented getopt parameters
From: Jem Berkes (jem_at_users.pc9__org)
Date: 10/30/03
- Next message: Rich Teer: "Re: DOOR_UNREF_MULTI question"
- Previous message: David Schwartz: "Re: send problems linux"
- In reply to: Jem Berkes: "Dealing with fragmented getopt parameters"
- Next in thread: William Ahern: "Re: Dealing with fragmented getopt parameters"
- Reply: William Ahern: "Re: Dealing with fragmented getopt parameters"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Oct 2003 02:16:43 GMT
> I have a C program that uses getopt. I added an -o switch that takes a
> parameter, and it works as expected when invoked from a shell:
> myprogram -g -o "sendmail -f sender recipient"
> That is, after parsing, optarg refers to everything within quotes
>
> I want to make it possible to call my program from postfix's pipe
> command. That documentation states that the command to execute has no
> shell-style interpretation. Sure enough, when I invoke postfix pipe's
> argv=myprogram -g -o "sendmail -f $(sender) $(recipient)"
> I saw experimentally that postfix delimits on spaces, quotes remain:
> -g
> -o
> "sendmail
> -f
> $(sender)
> $(recipient)"
>
> How can I work around this? One idea I had was to, after getopt
> iteration, check to see if optarg starts with a quote. This would
> imply that whatever invoked the command did not group things between
> "" as a single parameter. So then I can simply merge all subsequent
> argv[n]'s together, separating them by spaces.
>
> Does this seem like a good idea? Note that if the shell does properly
> group things within "" then the opening quote will not appear within
> optarg, and no special processing is required.
Terribly sorry, I meant this to go to comp.lang.c
- Next message: Rich Teer: "Re: DOOR_UNREF_MULTI question"
- Previous message: David Schwartz: "Re: send problems linux"
- In reply to: Jem Berkes: "Dealing with fragmented getopt parameters"
- Next in thread: William Ahern: "Re: Dealing with fragmented getopt parameters"
- Reply: William Ahern: "Re: Dealing with fragmented getopt parameters"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|