Problem in calling two perl scripts one after the other using "exec"

S

saki80

Hi All,
I am calling perl scripts b.pl & c.pl from a.pl which takes three
arguments. I want to pass these command line arguments to b.pl & c.pl
also. so i could not do this by using 'system'. so ito continue my
work that time i hardcoded the parameters while calling b.pl & c.pl as
shown below

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
a.pl
=========
..
..
..

system('b.pl', ip_address1);
system('c.pl', ip_address2, ip_address3);

where ip_address1, ip_address2 & ip_address3 are hardcoded vaules...

but if i use 'exec' in place of 'system', i could make use of the
ARGV(command line arguments for a.pl) as command line arguments for
b.pl & c.pl...

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
a.pl
=========
..
..
..

exec "b.pl", $ARGV[1];
exec "c.pl", $ARGV[0], $ARGV[2];

but the problem is if i call two exec's , only one is getting
called..but if i use one at a time by commenting the other it is
working fine.

How can i call two exec one after the other so that both will execute.

Rgds
SaiKiran
 
A

anno4000

Hi All,
I am calling perl scripts b.pl & c.pl from a.pl which takes three
arguments. I want to pass these command line arguments to b.pl & c.pl
also. so i could not do this by using 'system'.

Why do you say that?
so ito continue my
work that time i hardcoded the parameters while calling b.pl & c.pl as
shown below

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
a.pl
=========
.
.
.

system('b.pl', ip_address1);
system('c.pl', ip_address2, ip_address3);

where ip_address1, ip_address2 & ip_address3 are hardcoded vaules...

but if i use 'exec' in place of 'system', i could make use of the
ARGV(command line arguments for a.pl) as command line arguments for
b.pl & c.pl...

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
a.pl
=========
.
.
.

exec "b.pl", $ARGV[1];
exec "c.pl", $ARGV[0], $ARGV[2];

but the problem is if i call two exec's , only one is getting
called..but if i use one at a time by commenting the other it is
working fine.

How can i call two exec one after the other so that both will execute.

That's against the nature of exec(), it never returns. Read
"perldoc -f exec" and "perldoc -f system" (again).

Also note that system() and exec() have exactly the same parameters.
Just use system().

Anno
 
I

Ian Wilson

Hi All,
I am calling perl scripts b.pl & c.pl from a.pl which takes three
arguments. I want to pass these command line arguments to b.pl & c.pl
also. so i could not do this by using 'system'.

You can.

C:>perl -e "system 'echo', $ARGV[0], $ARGV[2]" foo bar baz qux
foo baz
but the problem is if i call two exec's , only one is getting
called..but if i use one at a time by commenting the other it is
working fine.

How can i call two exec one after the other so that both will execute.

You can't. Read the first sentence of `perldoc -f exec`.
 
S

saki80

Hi,
Thanks for the response..I don't want to pass all the command line
arguments to both the scripts, instead i want to pass 2nd argument to
b.pl & 1,3 arguments to c.pl...could u tell me how can i do this...

Saikiran.

Sherm said:
Hi All,
I am calling perl scripts b.pl & c.pl from a.pl which takes three
arguments. I want to pass these command line arguments to b.pl & c.pl
also. so i could not do this by using 'system'.

Sure you can - just pass the arguments.

system('b.pl', @ARGV);
exec "b.pl", $ARGV[1];
exec "c.pl", $ARGV[0], $ARGV[2];

but the problem is if i call two exec's , only one is getting
called..

No, exec() is behaving as documented. The problem is that you're expecting
it to do something other than what the docs say it will do.
How can i call two exec one after the other so that both will execute.

You can't. Read the documentation for the function you're trying to use:

perldoc -f exec

sherm--
 
D

DJ Stunks

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
exec "b.pl", $ARGV[1];
exec "c.pl", $ARGV[0], $ARGV[2];

C:\tmp>cat a.pl b.pl c.pl
#!/usr/bin/perl

use strict;
use warnings;

print "I am a.pl [\@ARGV = @ARGV]\n";

{
local @ARGV = $ARGV[1];
do 'b.pl';
}

{
local @ARGV = @ARGV[0,2];
do 'c.pl';
}

__END__

#!/usr/bin/perl

use strict;
use warnings;

print "I am b.pl [\@ARGV = @ARGV]\n";

__END__

#!/usr/bin/perl

use strict;
use warnings;

print "I am c.pl [\@ARGV = @ARGV]\n";

__END__

C:\tmp>a.pl 1.1.1.1 1.1.1.2 1.1.1.3
I am a.pl [@ARGV = 1.1.1.1 1.1.1.2 1.1.1.3]
I am b.pl [@ARGV = 1.1.1.2]
I am c.pl [@ARGV = 1.1.1.1 1.1.1.3]


-jp
 
T

Tad McClellan

I am calling perl scripts b.pl & c.pl from a.pl which takes three
arguments. I want to pass these command line arguments to b.pl & c.pl
also. so i could not do this by using 'system'.


Why not?

but the problem is if i call two exec's , only one is getting
called..but if i use one at a time by commenting the other it is
working fine.


That is how exec is _supposed_ to work.

How can i call two exec one after the other so that both will execute.


You cannot.


system() and exec() have the same syntax, they differ only
in their semantics.
 
I

Ian Wilson

Hi,
Thanks for the response..I don't want to pass all the command line
arguments to both the scripts, instead i want to pass 2nd argument to
b.pl & 1,3 arguments to c.pl...could u tell me how can i do this...

Don't you read the responses to your questions?
I already posted an example showing how to do this!
 
M

Mumia W. (reading news)

Hi All,
I am calling perl scripts b.pl & c.pl from a.pl which takes three
arguments. I want to pass these command line arguments to b.pl & c.pl
also. so i could not do this by using 'system'. so ito continue my
work that time i hardcoded the parameters while calling b.pl & c.pl as
shown below

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
a.pl
=========
..
..
..

system('b.pl', ip_address1);
system('c.pl', ip_address2, ip_address3);

where ip_address1, ip_address2 & ip_address3 are hardcoded vaules...

but if i use 'exec' in place of 'system', i could make use of the
ARGV(command line arguments for a.pl) as command line arguments for
b.pl & c.pl...

a.pl 1.1.1.1 1.1.1.2 1.1.1.3
a.pl
=========
..
..
..

exec "b.pl", $ARGV[1];
exec "c.pl", $ARGV[0], $ARGV[2];

but the problem is if i call two exec's , only one is getting
called..but if i use one at a time by commenting the other it is
working fine.

How can i call two exec one after the other so that both will execute.

Rgds
SaiKiran

Why not see if you can use $ARGV[...] with system?
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top