How to print all command args in open

Discussion in 'Perl Misc' started by sam, Mar 8, 2005.

  1. sam

    sam Guest

    Hi,

    I have the following open function calls some external programs but I do
    not know whether the commandline arguments are correct:

    open $fh, '|-', './irpt_gen_2.pl', '$DATE', '$f', 'out', '>',
    'invent-$DATE-$f.out';

    If I use a shell script to execute the above command, I would write
    something as follow:
    perl irpt_gen_2.pl 20-01-2005 KevinData/Inventory.txt out >invent-2.dat

    I need to verify whether the commandline arguments in open is the same
    as the commandlines as executed in the shell script.

    Thanks
    Sam
     
    sam, Mar 8, 2005
    #1
    1. Advertising

  2. sam

    sam Guest

    Christian Winter wrote:
    > sam wrote:
    >
    >> Hi,
    >>
    >> I have the following open function calls some external programs but I
    >> do not know whether the commandline arguments are correct:
    >>
    >> open $fh, '|-', './irpt_gen_2.pl', '$DATE', '$f', 'out', '>',
    >> 'invent-$DATE-$f.out';

    >
    >
    > Why not build an array with the arguments, then join() and print that?
    > my @cmdargs = ( './irpt_gen_2.pl',
    > '$DATE',
    > '$f',
    > 'out',
    > '>',
    > 'invent-$DATE-$f.out'
    > );
    > print "Command line: ", join( " ", @cmdargs );
    > open $fh, '|-', @cmdargs;
    >
    > Are $DATE and $f perl variables or shell variables? If it's the
    > first, you will want to use double quotes instead of single
    > quotes to allow variable interpolation.
    >

    Hi Chris, thanks for the prompt reply.
    The $DATE and $f are perl variables.
    But since the value of $DATE is start with number, the open command
    doesn't take it as a string when padding it to the commandlien args.
    eg. I expect something like the following should be executed in the
    open() perl function:
    ../irpt_gen_2.pl 8-3-2005 /usr/local/dc_data/test out >
    invent-8-3-2005-test.out
    But the irpt_gen_2.pl program only reads two arguments as shown below:
    ../irpt_gen_2.pl /usr/local/dc_data/test out > invent-8-3-2005-test.out

    The DATE is missing from the the commandline.

    Thanks
    Sam

    > HTH
    > -Chris
     
    sam, Mar 8, 2005
    #2
    1. Advertising

  3. sam

    sam Guest

    sam wrote:
    > Christian Winter wrote:
    >
    >> sam wrote:
    >>
    >>> Hi,
    >>>
    >>> I have the following open function calls some external programs but I
    >>> do not know whether the commandline arguments are correct:
    >>>
    >>> open $fh, '|-', './irpt_gen_2.pl', '$DATE', '$f', 'out', '>',
    >>> 'invent-$DATE-$f.out';

    >>
    >>
    >>
    >> Why not build an array with the arguments, then join() and print that?
    >> my @cmdargs = ( './irpt_gen_2.pl',
    >> '$DATE',
    >> '$f',
    >> 'out',
    >> '>',
    >> 'invent-$DATE-$f.out'
    >> );
    >> print "Command line: ", join( " ", @cmdargs );
    >> open $fh, '|-', @cmdargs;
    >>
    >> Are $DATE and $f perl variables or shell variables? If it's the
    >> first, you will want to use double quotes instead of single
    >> quotes to allow variable interpolation.
    >>

    > Hi Chris, thanks for the prompt reply.
    > The $DATE and $f are perl variables.
    > But since the value of $DATE is start with number, the open command
    > doesn't take it as a string when padding it to the commandlien args.
    > eg. I expect something like the following should be executed in the
    > open() perl function:
    > ./irpt_gen_2.pl 8-3-2005 /usr/local/dc_data/test out >
    > invent-8-3-2005-test.out
    > But the irpt_gen_2.pl program only reads two arguments as shown below:
    > ./irpt_gen_2.pl /usr/local/dc_data/test out > invent-8-3-2005-test.out
    >
    > The DATE is missing from the the commandline.
    >

    I just found that when pass the argments of above open command args to
    an external perl program (irpt_gen_2.pl) from the above perl code, the
    external perl program count the ARGV as 4, while execute the external
    perl program with the same args from the Unix shell, the irpt_gen_2.pl
    count it as 2.

    Sam.

    > Thanks
    > Sam
    >
    >> HTH
    >> -Chris
     
    sam, Mar 8, 2005
    #3
  4. sam

    Anno Siegel Guest

    sam <> wrote in comp.lang.perl.misc:
    > Christian Winter wrote:
    > > sam wrote:
    > >
    > >> Hi,
    > >>
    > >> I have the following open function calls some external programs but I
    > >> do not know whether the commandline arguments are correct:
    > >>
    > >> open $fh, '|-', './irpt_gen_2.pl', '$DATE', '$f', 'out', '>',
    > >> 'invent-$DATE-$f.out';

    > >
    > >
    > > Why not build an array with the arguments, then join() and print that?
    > > my @cmdargs = ( './irpt_gen_2.pl',
    > > '$DATE',
    > > '$f',
    > > 'out',
    > > '>',
    > > 'invent-$DATE-$f.out'
    > > );
    > > print "Command line: ", join( " ", @cmdargs );
    > > open $fh, '|-', @cmdargs;
    > >
    > > Are $DATE and $f perl variables or shell variables? If it's the
    > > first, you will want to use double quotes instead of single
    > > quotes to allow variable interpolation.
    > >

    > Hi Chris, thanks for the prompt reply.
    > The $DATE and $f are perl variables.
    > But since the value of $DATE is start with number, the open command
    > doesn't take it as a string when padding it to the commandlien args.


    This is nonsense.

    > eg. I expect something like the following should be executed in the
    > open() perl function:
    > ./irpt_gen_2.pl 8-3-2005 /usr/local/dc_data/test out >
    > invent-8-3-2005-test.out
    > But the irpt_gen_2.pl program only reads two arguments as shown below:
    > ./irpt_gen_2.pl /usr/local/dc_data/test out > invent-8-3-2005-test.out


    How did you know determine what irpt_gen_2.pl gets to see?

    Have you followed Christian's advice? What does

    print "Command line: @cmdargs\n"

    show?

    Anno
     
    Anno Siegel, Mar 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    637
    Ken Varn
    Jun 22, 2005
  2. Replies:
    3
    Views:
    498
    David Eppstein
    Sep 17, 2003
  3. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    698
    Pierre Fortin
    Sep 18, 2004
  4. er
    Replies:
    2
    Views:
    509
  5. Andrew Tomazos
    Replies:
    5
    Views:
    582
Loading...

Share This Page