How to use debugger on perl script executed by "exec" - perl

I trying to figure out how a Perl script which is doing test status reporting, is working. The script executes another piece of perl script via exec. I am able single step through code in first script but when it hits exec, the script executed by exec runs till completion. Is there a way by which I will be able single step and look at variables in the script executed by exec?

Add below to the script which is being called with exec
#!/usr/bin/perl -d

Related

Run perl script from tcl

I have a perl script that I manually run it from shell:
myScript.pl -from_session=Session1234 -to_session=Session6789 -port=104:3445
I try to run it from tcl, in this way, but it doesn't work....
set script_path "myScript.pl";
set sessionA "Session1234";
set sessionB "Session6789";
set p "104:3445";
exec perl $script_path -from_session=$sessionA -to_session=$sessionB -port=$p
Update:
I found that the perl script is done, but the tcl script is not continue after the execution of the perl script.
TCL doesn't need semicolon at the end. Once removed, I tried to execute exec command on one of my PERL script in tclsh and it works fine.
Therefore my suggestion is to try executing the program in tclsh to see weather some error is returned and most importantly to give the full absolute path to the script. All in all, try
set script_path "/absolute/path/to/myScript.pl"
set sessionA "Session1234"
set sessionB "Session6789"
set p "104:3445"
exec perl $script_path -from_session=$sessionA -to_session=$sessionB -port=$p

Running /scripts/pkgacct using system(), exec() or backticks

I have a small perl script which runs the /scripts/pkgacct command in cPanel using system(). The code looks like so;
print "\n/scripts/pkgacct --skiphomedir --nocompress $acc_name /my_backup\n\n";
system("/scripts/pkgacct --skiphomedir --nocompress $acc_name /my_backup");
my $bk_path = "/my_backup/cpmove-$acc_name.tar";
system("tar -xvf $bk_path -C /my_backup/");
When I run the script, only cPanel's default roundcube and horde databases are backed up. When I replace system() with exec"", the script runs as expected but terminates as soon as exec is executed, i.e the subsequent statements in the perl script aren't executed. Using backticks shows the same behaviour as system() - i.e doesn't backup all the databases.
Could someone tell me what mistake I am making?
Alternately, how can I get the remaining statements to execute after the exec command?
Try using system like so:
system('/scripts/pkgacct', '--skiphomedir', '--nocompress', $acc_name, '/my_backup');
I've found that system works best when you break up the command and parameters like it expects.
Try using IPC::Run (https://metacpan.org/pod/IPC::Run). Your code would look something like:
use IPC::Run qw(run);
print "\n/scripts/pkgacct --skiphomedir --nocompress $acc_name /my_backup\n\n";
run ['/scripts/pkgacct', '--skiphomedir', '--nocompress', $acc_name];
my $bk_path = "/my_backup/cpmove-$acc_name.tar";
run ['tar','-xvf',$bk_path,'-C','/my_backup/'];

How to invoke Unix "script" command in Perl?

I'm sure this is an easy fix, but I need to use "script" (and not collect standard in/out/error) for my project. I'm somewhat new to Perl, so please bear with me.
I have a Perl script that works fine. When I run it I generally type script > filename before I run Perl.
$script > file.log
bash-3.2$ perl foobar.pl
This runs fine, and when I'm done I type exit or control D to stop the script and save the file. All I'd like to do is incorporate the script command in Perl and then automatically capture the file when the program stops running (12-16 hours). The problem I have is that is I call in system("script > file.log"); and them call system("perl foobar.pl"); it hangs at the bash-3.2$ prompt. The only way to get Perl to work is control D or exit, stopping the script function.
Anyone have any idea how to fix this? While it's easy to start with script before invoking Perl, if I'm a mole and forget, I have to rerun the program (which takes a long time).
Have you considered using system("script -c 'perl foobar.pl' file.log")?

Returning handle to calling script perl

I have an executable which can run perl scripts using the following command at the prompt:
blah.exe Launch.pl
The way we have our tests setup is that we call the Launch.pl from Parent.pl like this "blah.exe Launch.pl" - script within script. However, when executing the command with backticks/system command the parent .pl script execution waits till I get the handle back by closing and exiting out of the application (blah.exe). At this point the code in parent.pl continues to execute.
How do I return the handle back to the parent .pl script after I get done running the code that is contained in the Launch.pl
So, parent.pl calls "blah.exe Launch.pl"; but after running the code inside Launch.pl inside the application (blah.exe) it just sits there waiting to be exited out of so that the code in parent.pl can continue running. I need to keep the application (blah.exe) open till I am done running a bunch of scripts one after another.
Run blah.exe in the background. When you are done with the Parent.pl, terminate the application with kill.

Running ksh script inside a perl code is not working

I have a Korn shell script at a location like /opt/apps/abc/folder/properties.env. I can execute it from Unix bash using the dot command:
. /opt/apps/abc/folder/properties.env
This works.
I have a Perl script abc.pl from which I am calling the script properties.env. I tried the following different:
system('/usr/bin/ksh','-c', '. /opt/apps/abc/folder/properties.env');
/usr/bin/ksh -c /opt/apps/abc/folder/properties.env;
system('. /opt/apps/abc/folder/properties.env');
None of the above work. I don't want to use exec because I want to return to the Perl script. What am I doing wrong?
The environment changes will only last as long as the life of the ksh session spawned by the system command. If you want the environment changes to affect the Perl script, then you have to source that file before you launch the Perl program.
If you need those environment variables in your perl code, (not in the environment where you called perl), you can also read and parse that properties.env and set the environment in the %ENV variable.
e.g
$ENV{'ENV_VAR1'}=VALUE_OF_ENV_VAR1
using system() spawn another process, as the other poster said. changing environment in the child does not affect the parent.