Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Piping a System commmand to a Perl variable...

Status
Not open for further replies.

juanmj

Technical User
Nov 13, 2001
5
US
Hi,

I want to be able to obtain the output of a system command to a perl variable ..

Example:
Something like this:

my $variable = system ("users");

But what I want in the variable is the output of the executed system command "users"...

Any Ideas???

Thanks ....


 
Backticks is a good way of accomplishing this, for example:
my $variable = ´users´;
would capture teh output and put it in the scalar variable.
//Daniel
 
<grin> Pardon me Daniel but those are forward ticks..... I think you mean:

my $variable = `users`;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Better way if you have multiple lines:

open (IN, &quot;users|&quot;);
while (<IN>) {
do something interesting...
}
close (IN)
 
<grin> Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks a lot for your posts...

It helped just great....


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top