Home: Perl Programming Help: Beginner:
how to print out variables of a command



regex2012
User

Aug 17, 2016, 7:33 AM


Views: 2757
how to print out variables of a command

I am trying to find out what the following command sees when it prints out

Code
my $command=qx(/usr/sbin/apptracer -id "${listid}" -d "${date}" -rx 2)


What I have done is verified that $listid does print out an id when not in this command - as a separate variable.

$date also prints out the proper date. However, when this qx command runs, it does not return anything. If I enter the listid and the date without the command being in a script, it does return the proper data.

I am thinking that there could be spaces that are getting into the variables or something that I can't see that are getting into the command arguments $listid and $date when they are being run by the script.

However, I can't test this as I need to find a way to print out the $listid and $date as the command is seeing it when it runs.


FishMonger
Veteran / Moderator

Aug 17, 2016, 8:20 AM


Views: 2753
Re: [regex2012] how to print out variables of a command

I'd start by removing the braces from the vars since they are unneeded in this case.

Assign your full command to a var and then use that var in the qx(..) statement. This will allow you to print the command prior to executing it to verify that it is constructed the way you intended.


Code
my $cmd = qq(/usr/sbin/apptracer -id "$listid" -d "$date" -rx 2); 
print $cmd, $/;

my cmd_output = qx($cmd);



Laurent_R
Veteran / Moderator

Aug 17, 2016, 10:38 AM


Views: 2747
Re: [FishMonger] how to print out variables of a command


In Reply To

Code
 
my cmd_output = qx($cmd);



Just a small typo: cmd_output needs a sigil. It could be $cmd_output or @cmd_output, depending on what the command returns and the way it should be processed.


regex2012
User

Aug 18, 2016, 9:24 AM


Views: 2719
Re: [Laurent_R] how to print out variables of a command

Thanks, all! worked like a charm!