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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple problem

Status
Not open for further replies.

FredrikN

Programmer
Jan 5, 2001
60
SE
Hi.

I have a little problem, I can't store the systemcommand to an variable.

Let say this perl script

#!/usr/bin/perl

$tmp = system ("ls");
print "The dir stuff is $tmp";


This script will first show the output from the $tmp = system ("ls"); line and then print "The dir stuff is 0"

How can I store the output from system("xxx") into one variable ??

And I don't want the $tmp = system ("ls"); line to print anything.


I want the output to be like

The dir stuff is

xxxxxxx xxxxxxxx xxxxxxxxx xxx
xxxxxxx xxxxxxxx xxxxxxxxx xxx

until the end.


Thanks in advance

 
I have done something like this before. Probably not the answer you are looking for.

$var = `ls`;###these are ticks
print "$var";
 
Hi and Thanks.

It worked fine :))

//FredrikN
 
The reason you are getting "0" returned is that the system command doesn't return the output from the command, it executes the command and returns the return code from the command, shifted left by 8 bits. All you are doing with the system command is finding out that it executed successfully (returned a 0 return code). Stiddy gave the correct method for doing what you want, except the comment should have said ###these are backticks. If you use ticks then $var will have the value "ls".
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Sorry FredrikN, tsdragon is correct....I should have said backticks. Thanks for the correction tsdragon!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top