home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!convex!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: stdout from 'system'?
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Sep10.183248.21125@news.eng.convex.com>
- Date: Thu, 10 Sep 1992 18:32:48 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <1180030@hpcc01.corp.hp.com>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 32
-
- From the keyboard of lynch@hpcc01.corp.hp.com (Howard Lynch):
- :Specific: I want to get the hostname of the system my perl script is running
- : on into a script variable.
- :
- : The ksh equivalent would be:
- :
- : HOST=`hostname`
- : echo $HOST
- :
- : The best way I can figure out to do this with perl is:
- :
- : open(ASDF,"hostname|");
- : chop($hostname=<ASDF>);
- : close(ASDF);
- : print "hostname = $hostname";
- :
- :General: I want to get the stdout from a unix command into a script variable.
- : It would seem like I should be able to use the 'system' command
- : and capture its stdout into a script variable.
-
- You've forgotten that backticks work in perl:
-
- print "hostname = ", `hostname`;
-
- Note that the newline will be left intact.
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
- It won't be covered in the book. The source code has to be useful for
- something, after all... :-)
- --Larry Wall in <10160@jpl-devvax.JPL.NASA.GOV>
-