Re: Dealing with fragmented getopt parameters

From: Jem Berkes (jem_at_users.pc9__org)
Date: 10/30/03


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



Relevant Pages

  • Re: Dealing with fragmented getopt parameters
    ... > I have a C program that uses getopt. ... That documentation states that the command to execute has no ... when I invoke postfix pipe's ... > I saw experimentally that postfix delimits on spaces, quotes remain: ...
    (comp.lang.c)
  • Re: Dealing with non-grouped getopt parameters
    ... when I invoke postfix pipe's ... During the getopt iteration, it would encounter -o and at ... that point optarg would point to '"sendmail' (note the visible quotes) ...
    (comp.unix.programmer)
  • Dealing with fragmented getopt parameters
    ... I have a C program that uses getopt. ... when I invoke postfix pipe's ... I saw experimentally that postfix delimits on spaces, quotes remain: ... Note that if the shell does properly group ...
    (comp.unix.programmer)
  • missing command line argument in vb.net console app
    ... I invoke my program with three command line arguments, ... Here is the command line. ... I tried putting the last arg in quotes but ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Genuine Advantage -- Indeed?
    ... SEND command would then automatically invoke the MAIL command. ... exec, fully logged in. ...
    (rec.arts.sf.fandom)