CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



regex2012
User

Aug 17, 2016, 7:33 AM

Post #1 of 4 (1872 views)
how to print out variables of a command Can't Post

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

Post #2 of 4 (1868 views)
Re: [regex2012] how to print out variables of a command [In reply to] Can't Post

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

Post #3 of 4 (1862 views)
Re: [FishMonger] how to print out variables of a command [In reply to] Can't Post


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

Post #4 of 4 (1834 views)
Re: [Laurent_R] how to print out variables of a command [In reply to] Can't Post

Thanks, all! worked like a charm!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives