LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-23-2008, 11:02 AM   #1
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Rep: Reputation: 15
Question 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:

Code:
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???
 
Old 05-23-2008, 11:30 AM   #2
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 509

Rep: Reputation: 41
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..)
 
Old 05-23-2008, 12:10 PM   #3
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
Question

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

Code:
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??????
 
Old 05-23-2008, 12:47 PM   #4
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
Question

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

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl:Not able to execute command in variable jags.singh Programming 1 07-23-2007 07:51 AM
Problem with perl script using a variable from a unix command. abefroman Programming 1 05-11-2006 05:11 PM
exec cmd=perl... work but exec cgi doenst crions Slackware 5 12-09-2005 12:17 PM
php: output the result of exec( $command ) zovres Programming 6 08-27-2004 06:41 PM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM


All times are GMT -5. The time now is 09:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration