home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5841 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.8 KB  |  50 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: stdout from 'system'?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Sep10.183248.21125@news.eng.convex.com>
  8. Date: Thu, 10 Sep 1992 18:32:48 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <1180030@hpcc01.corp.hp.com>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 32
  17.  
  18. From the keyboard of lynch@hpcc01.corp.hp.com (Howard Lynch):
  19. :Specific:  I want to get the hostname of the system my perl script is running
  20. :           on into a script variable.
  21. :
  22. :           The ksh equivalent would be:
  23. :
  24. :                HOST=`hostname`
  25. :                echo $HOST
  26. :
  27. :           The best way I can figure out to do this with perl is:
  28. :
  29. :               open(ASDF,"hostname|");
  30. :               chop($hostname=<ASDF>);
  31. :               close(ASDF);
  32. :               print "hostname = $hostname";
  33. :
  34. :General:  I want to get the stdout from a unix command into a script variable.
  35. :          It would seem like I should be able to use the 'system' command
  36. :          and capture its stdout into a script variable.
  37.  
  38. You've forgotten that backticks work in perl:
  39.  
  40.     print "hostname = ", `hostname`;
  41.  
  42. Note that the newline will be left intact.
  43.  
  44. --tom
  45. -- 
  46.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  47.     It won't be covered in the book.  The source code has to be useful for
  48.     something, after all...  :-)
  49.             --Larry Wall in <10160@jpl-devvax.JPL.NASA.GOV>
  50.