Calling Different scripts with 1 wrapper script

Q

qazmlp

Kindly guide me in implementing the following:

A directory will have the following files: -

script1 -> ./wrapper.pl
script2 -> ./wrapper.pl
script3 -> ./wrapper.pl
wrapper.pl
script1.pl
script2.pl
script3.pl

script1, script2 & script3 are links to same PERL script:wrapper.pl.
Application users will be using either of script1,script2, script3 only.
wrapper.pl should be written in such a way that,
- whenever script1 is invoked by the user, script1.pl should be called
automatically
Similarly, script2.pl, script3.pl respectively for the invocation of
script2, script3.

How exactly this can be achieved?
 
L

Lars Eighner

In our last episode,
the lovely said:
Kindly guide me in implementing the following:
A directory will have the following files: -
script1 -> ./wrapper.pl
script2 -> ./wrapper.pl
script3 -> ./wrapper.pl
wrapper.pl
script1.pl
script2.pl
script3.pl
script1, script2 & script3 are links to same PERL script:wrapper.pl.
Application users will be using either of script1,script2, script3 only.
wrapper.pl should be written in such a way that,
- whenever script1 is invoked by the user, script1.pl should be called
automatically
Similarly, script2.pl, script3.pl respectively for the invocation of
script2, script3.
How exactly this can be achieved?

I believe if you consult perlvar you will find $0 may be
suitable for your purposes.

for example:

if print.pl =
#!/usr/local/bin/perl -w

print "$0\n";
#end

and link.pl is a symbolic link to print.pl

then
perl link.pl

should produce:
link.pl

while
perl print.pl
produces
print.pl

It seems to me, then that you can test $0 to determine how your
script was invoked.
 
P

Paul Lalli

qazmlp said:
Kindly guide me in implementing the following:

A directory will have the following files: -

script1 -> ./wrapper.pl
script2 -> ./wrapper.pl
script3 -> ./wrapper.pl
wrapper.pl
script1.pl
script2.pl
script3.pl

script1, script2 & script3 are links to same PERL script:wrapper.pl.
Application users will be using either of script1,script2, script3 only.
wrapper.pl should be written in such a way that,
- whenever script1 is invoked by the user, script1.pl should be called
automatically
Similarly, script2.pl, script3.pl respectively for the invocation of
script2, script3.

How exactly this can be achieved?

At least on my system, $0 in the wrapper.pl script reports the name of
the link whose name was typed on the command line, not wrapper.pl.

So in wrapper.pl, you should examine the value of $0 to determine which
link the user called:

if ($0 =~ /script1$/) {
#do something with script1.pl
} elsif ($0 =~ /script2$/) {
#do something with script2.pl
} #etc

Or, if the names of your links really are the names you listed, use a
regexp to determine which one:
if ($0 =~ /script(\d+)$/){
$filename = script$1.pl;
#do something with $filename;
}

Hope this helps,
Paul Lalli
 
T

Tad McClellan

script1, script2 & script3 are links to same PERL script:wrapper.pl.
Application users will be using either of script1,script2, script3 only.
wrapper.pl should be written in such a way that,
- whenever script1 is invoked by the user, script1.pl should be called
automatically
Similarly, script2.pl, script3.pl respectively for the invocation of
script2, script3.

How exactly this can be achieved?


By examining the value of the $0 variable, see:

perldoc perlvar
 
A

Anno Siegel

qazmlp said:
Kindly guide me in implementing the following:

A directory will have the following files: -

script1 -> ./wrapper.pl
script2 -> ./wrapper.pl
script3 -> ./wrapper.pl
wrapper.pl
script1.pl
script2.pl
script3.pl

script1, script2 & script3 are links to same PERL script:wrapper.pl.
Application users will be using either of script1,script2, script3 only.
wrapper.pl should be written in such a way that,
- whenever script1 is invoked by the user, script1.pl should be called
automatically
Similarly, script2.pl, script3.pl respectively for the invocation of
script2, script3.

That looks like a rather convoluted way of calling three scripts that are
perfectly callable on their own.
How exactly this can be achieved?

If you must, use $0 (see perlvar) and File::Basename to get the name
the script was called by and branch on it. The "exactly" part is left
as an exercise.

Anno
 
M

Michael Meissner

Dave Weaver said:
IMHO this would be better written as:

if ( $0 eq 'script1' ) {
... etc ...

No it wouldn't. Consider typing /foo/bar/script1 vs. ./script1 vs
.../bar/script1. On many shells, what you type in as the command is what is
put in ARGV[0], which perl stripps off to $0. I would imagine different shells
might also put different forms of the pathname in different cases.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top