Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to print all command args in open

Reply
Thread Tools

How to print all command args in open

 
 
sam
Guest
Posts: n/a
 
      03-08-2005
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
 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      03-08-2005
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

 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      03-08-2005
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

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      03-08-2005
sam <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
C++0x -- fun(Args&...) and fun(Args const&...) er C++ 2 12-20-2010 07:52 PM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments