How to print all command args in open

S

sam

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
 
S

sam

Christian said:
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
 
S

sam

sam said:
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.
 
A

Anno Siegel

sam said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top