Dealing with fragmented getopt parameters
From: Jem Berkes (jem_at_users.pc9__org)
Date: 10/30/03
- Previous message: Michael Fuhr: "Re: DOOR_UNREF_MULTI question"
- Next in thread: Jem Berkes: "Re: Dealing with fragmented getopt parameters"
- Reply: Jem Berkes: "Re: Dealing with fragmented getopt parameters"
- Reply: TCL: "Re: Dealing with fragmented getopt parameters"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Oct 2003 00:22:00 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.
-- Jem Berkes http://www.sysdesign.ca/
- Previous message: Michael Fuhr: "Re: DOOR_UNREF_MULTI question"
- Next in thread: Jem Berkes: "Re: Dealing with fragmented getopt parameters"
- Reply: Jem Berkes: "Re: Dealing with fragmented getopt parameters"
- Reply: TCL: "Re: Dealing with fragmented getopt parameters"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|