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

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!park.uvcc.edu!ns.novell.com!jkt
  3. From: jkt@SED.Provo.Novell.COM (Jack Thomasson)
  4. Subject: Re: stdout from 'system'?
  5. In-Reply-To: lynch@hpcc01.corp.hp.com's message of Wed, 9 Sep 1992 23:01:34 GMT
  6. Message-ID: <JKT.92Sep13005356@seneca.SED.Provo.Novell.COM>
  7. Sender: usenet@Novell.COM (Usenet News)
  8. Nntp-Posting-Host: seneca.sed.provo.novell.com
  9. Organization: Novell, Inc.
  10. References: <1180030@hpcc01.corp.hp.com>
  11. Date: Sun, 13 Sep 1992 07:53:56 GMT
  12. Lines: 46
  13.  
  14. >>>>> On Wed, 9 Sep 1992 23:01:34 GMT, lynch@hpcc01.corp.hp.com
  15. >>>>> (Howard Lynch) said:
  16.  
  17. Howard> Specific: I want to get the hostname of the system my perl
  18. Howard> script is running on into a script variable.
  19.  
  20. use the backticks operator!
  21.  
  22. Howard>            The ksh equivalent would be:
  23.  
  24. Howard>                 HOST=`hostname`
  25. Howard>                 echo $HOST
  26.  
  27. and the perl equivalent is:
  28.  
  29. chop($HOST = `hostname`);        # remove trailing newline also
  30.  
  31. Howard> General: I want to get the stdout from a unix command into a
  32. Howard> script variable.  It would seem like I should be able to use
  33. Howard> the 'system' command and capture its stdout into a script
  34. Howard> variable.
  35.  
  36. $OUTPUT = `command`;
  37.  
  38. or
  39.  
  40. @OUTPUT = `command`;
  41.  
  42. just be careful: perl will gladly (now how did Larry put it?  man
  43. perl; ah, yes!) "slurp in your whole file as a single string".  i
  44. wouldn't recommend:
  45.  
  46. $OUTPUT = `find / -exec cat {} \;`;
  47.  
  48. Howard> Thanks for any feedback.
  49.  
  50. Howard> Howard Lynch
  51. Howard> HP OCD IC Manufacturing
  52. Howard> hl@hpocia.sj.hp.com
  53. --
  54. ---------------------------------------------------------------------
  55. Jack Thomasson                   :{)}               (the bearded one)
  56. Internet:Jack_Thomasson@Novell.COM                     MHS:JKT@NOVELL
  57. Novell Consulting Services\E-23-2\122 East 1700 South\Provo, UT 84606
  58. Phone: (800)453-1267x7604 | (801)429-7604          FAX: (801)429-5511
  59. "WARNING: the comments do not necessarily reflect the implementation"
  60.