-   Programming (
-   -   How to pass a result of exec command in perl to a variable??? (

HyperTrey 05-23-2008 11:02 AM

How to pass a result of exec command in perl to a variable???
I am attempting to pass the result of a perl comm of:


exec("host $ip \| awk \'\{print \$NF\}\'");
to a variable of $pcname. However I can not seem to get it to work correctly, how would i accomplish this???

Su-Shee 05-23-2008 11:30 AM

Read perldoc -f exec carefully. :)

(And try "system" afterwards - but honestly: this looks like something to me, which can be easily solved in Perl entirely..)

HyperTrey 05-23-2008 12:10 PM

now sure how to handle this, but I do see where system works better and the exec should be at the end. We dont want to load any extra perl modules (not my call)

want to be able to set the value of $psname with the result of


system("host $ip \| awk \'\{print \$NF\}\'");
I would ask as much however doing all the searching on the net yeilds me nothing, but i did fins a good deal on a pearl handled chainsaw (still wondering how that has anything to do with what i am looking for).

I tried doing $pcname = (system("host $ip \| awk \'\{print \$NF\}\'")); however it still prints the info to the screen and never sets the variable. How do I set the result to the variable??????

HyperTrey 05-23-2008 12:47 PM

I actually just got it. Using backticks and the following code:


$host = `host $ip | awk '{print \$NF}'`;

All times are GMT -5. The time now is 11:48 AM.