Discussion:
multiple perl script together
(too old to reply)
Bagdevi
2014-07-22 07:45:19 UTC
Permalink
Dear Group,

I am trying to make a group of perl script, bundle up together to act
inside one executable. I know I can bundle up multiple perl script together
as follows.

pp -o a.exe a.pl b.pl c.pl

I can unzip the a.exe and see that a.pl, b.pl and c.pl are inside the
script/ folder.

My problem is, I want to run b.pl and c.pl from inside a.pl. In the script
a.pl I have lines of code such as follows:
system ("perl b.pl" );
system ("perl c.pl d 1>out 2>error");

And I want that I should be able to run b.pl and c.pl from a.pl, according
to what the user selects in the GUI.

pp -o a.exe a.pl b.pl c.pl :did not work
pp -o a.exe a.pl -a b.pl -a c.pl :also did not work

I tried to change the system commands in a.pl as follows:

system ("perl script/b.pl" );
system ("perl script/c.pl d 1>out 2>error");

This also does not work.

Please suggest how to deal with it.

Thanks a lots for your help and time,


Regards,
Bagdevi Mishra.
David Mertens
2014-07-24 13:10:09 UTC
Permalink
Bagdevi,

If you rename the par-packed executable to "b.exe", then running it as "b"
should invoke the "b.pl" script. That is, the perl script that gets invoked
depends on the name of the executable itself. You can achieve the same end
on Unixen without renaming by using links; I am not sure if this works on
Windows, but I would be curious to know. :-)

FYI, my information comes from a similar question
<https://metacpan.org/pod/distribution/PAR/lib/PAR/Tutorial.pod#Aggregating-multiple-programs>
posed
in the Tutorial.

Hope that helps!
David
Post by Bagdevi
Dear Group,
I am trying to make a group of perl script, bundle up together to act
inside one executable. I know I can bundle up multiple perl script together
as follows.
pp -o a.exe a.pl b.pl c.pl
I can unzip the a.exe and see that a.pl, b.pl and c.pl are inside the
script/ folder.
My problem is, I want to run b.pl and c.pl from inside a.pl. In the
system ("perl b.pl" );
system ("perl c.pl d 1>out 2>error");
And I want that I should be able to run b.pl and c.pl from a.pl,
according to what the user selects in the GUI.
pp -o a.exe a.pl b.pl c.pl :did not work
pp -o a.exe a.pl -a b.pl -a c.pl :also did not work
system ("perl script/b.pl" );
system ("perl script/c.pl d 1>out 2>error");
This also does not work.
Please suggest how to deal with it.
Thanks a lots for your help and time,
Regards,
Bagdevi Mishra.
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
Ron W
2014-07-24 16:54:56 UTC
Permalink
Post by David Mertens
Bagdevi,
If you rename the par-packed executable to "b.exe", then running it as "b"
should invoke the "b.pl" script. That is, the perl script that gets
invoked depends on the name of the executable itself. You can achieve the
same end on Unixen without renaming by using links; I am not sure if this
works on Windows, but I would be curious to know. :-)
I think the key is the value of what the *underlying* ARGV[0] (what Perl
puts in$0) passed to the executable by exec.

MS Windows Vista and newer support symbolic links like what "ln -s" creates
on Linux/Unix/POSIX/etc. I don't know whether MS Windows' exec will put the
supplied filename or the name of the file targeted by the symlink into the
ARGV[0] it provides to the executable.

As far as I know, even in the latest versions, MS Windows NTFS does not
have "inodes" like Linux/Unix/etc use. Rather, it keeps that information in
the directory for each file. As such, a "hard link" in MS Windows is not
possible.
Bagdevi
2014-07-25 05:55:34 UTC
Permalink
Thanks a lot David and Ron,
I am aware of this way of bundling of multiple and running them by hard
linking, but my issue is bit different.

I have several script, one is master script and the others are called from
inside the master script.

one can imagine the structure as follows.

master.pl
-------------------

print "I am the master";
system ("perl a.pl");
system ("perl b.pl");


a.pl
------
print "I am the script a.pl";

b.pl
------
print "I am the script b.pl";



(For some reason, I can not put a.pl and b.pl as subrutine in the master.pl
.)

When I bundle them together using par-packer, i get master.pl, a.pl and b.pl
in the ./script folder. The resulting executable is master.exe as i need to
execute it externally. I want a.pl and b.pl should be able to run from
inside master.pl, which is not happening.
I tried the change the master.pl as follows:

master.pl
-------------------

print "I am the master";
system ("perl script/a.pl");
system ("perl script/b.pl");


This also does not do the job.

In each case, the error message is "perl scripts a.pl and b.pl not found."



Regards,
Bagdevi Mishra.
Post by Ron W
Post by David Mertens
Bagdevi,
If you rename the par-packed executable to "b.exe", then running it as
"b" should invoke the "b.pl" script. That is, the perl script that gets
invoked depends on the name of the executable itself. You can achieve the
same end on Unixen without renaming by using links; I am not sure if this
works on Windows, but I would be curious to know. :-)
I think the key is the value of what the *underlying* ARGV[0] (what Perl
puts in$0) passed to the executable by exec.
MS Windows Vista and newer support symbolic links like what "ln -s"
creates on Linux/Unix/POSIX/etc. I don't know whether MS Windows' exec will
put the supplied filename or the name of the file targeted by the symlink
into the ARGV[0] it provides to the executable.
As far as I know, even in the latest versions, MS Windows NTFS does not
have "inodes" like Linux/Unix/etc use. Rather, it keeps that information in
the directory for each file. As such, a "hard link" in MS Windows is not
possible.
Roderich Schupp
2014-07-25 13:47:53 UTC
Permalink
Post by Bagdevi
system ("perl a.pl");
There are several things wrong with this:

- You assume that a.pl is in your current working directory - that doesn't
have
to be the case even in the unpacked case.
In the packed case a.pl etc will be located in a temporary cache
directory,
"$ENV{PAR_TEMP}/inc/script"

- You assume that master.pl was invoked from an executable called "perl"
(or "perl.exe" on Windows) that can be found via $PATH - what if it's not
in your path and you called it with an absolute pathname? What if it's
not even called "perl", but "perl5.18" or similar?

Always use $^X which is the absolute pathname of the Perl interpreter that
is executing the current script.

- When packing, you must use "pp --reusable ..." for your scenario to work.

Putting all this together:

==> a.pl <==
#!/usr/bin/perl

use File::Spec;
my $script_dir = File::Spec->catdir($ENV{PAR_TEMP}, qw(inc script));
print STDERR "this is a.pl\n",
"\$script_dir = $script_dir\n";
"\$^X = $^X\n";

print STDERR "running b.pl ...\n";
system $^X, File::Spec->catfile($script_dir, "b.pl");

print STDERR "running c.pl ...\n";
system $^X, File::Spec->catfile($script_dir, "c.pl");

print STDERR "a.pl done\n";

==> b.pl <==
#!/usr/bin/perl
print STDERR "this is b.pl\n";

==> c.pl <==
#!/usr/bin/perl
print STDERR "this is c.pl\n";

... pack it...

$ pp --reusable -o foo.exe a.pl b.pl c.pl

...run it

$ ./foo.exe

this is a.pl
$script_dir =
/tmp/par-726f646572696368/cache-2a74a667f0a6e1a744c1654f442a69b2b563f710/inc/script
running b.pl ...
this is b.pl
running c.pl ...
this is c.pl
a.pl done


Cheers, Roderich
David Mertens
2014-07-26 12:20:50 UTC
Permalink
I'm sure I'm not alone in thinking that there is likely to be a better
design for your goal than this. However, I will refrain from offering
suggestions until you ask. :-)
Post by Bagdevi
Thanks a lot David and Ron,
I am aware of this way of bundling of multiple and running them by hard
linking, but my issue is bit different.
I have several script, one is master script and the others are called from
inside the master script.
one can imagine the structure as follows.
master.pl
-------------------
print "I am the master";
system ("perl a.pl");
system ("perl b.pl");
a.pl
------
print "I am the script a.pl";
b.pl
------
print "I am the script b.pl";
(For some reason, I can not put a.pl and b.pl as subrutine in the
master.pl.)
When I bundle them together using par-packer, i get master.pl, a.pl and
b.pl in the ./script folder. The resulting executable is master.exe as i
need to execute it externally. I want a.pl and b.pl should be able to run
from inside master.pl, which is not happening.
master.pl
-------------------
print "I am the master";
system ("perl script/a.pl");
system ("perl script/b.pl");
This also does not do the job.
In each case, the error message is "perl scripts a.pl and b.pl not found."
Regards,
Bagdevi Mishra.
Post by Ron W
Post by David Mertens
Bagdevi,
If you rename the par-packed executable to "b.exe", then running it as
"b" should invoke the "b.pl" script. That is, the perl script that gets
invoked depends on the name of the executable itself. You can achieve the
same end on Unixen without renaming by using links; I am not sure if this
works on Windows, but I would be curious to know. :-)
I think the key is the value of what the *underlying* ARGV[0] (what Perl
puts in$0) passed to the executable by exec.
MS Windows Vista and newer support symbolic links like what "ln -s"
creates on Linux/Unix/POSIX/etc. I don't know whether MS Windows' exec will
put the supplied filename or the name of the file targeted by the symlink
into the ARGV[0] it provides to the executable.
As far as I know, even in the latest versions, MS Windows NTFS does not
have "inodes" like Linux/Unix/etc use. Rather, it keeps that information in
the directory for each file. As such, a "hard link" in MS Windows is not
possible.
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
Loading...