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

How to load the return of system into a variable?

Status
Not open for further replies.

veteq

Technical User
Dec 7, 2004
23
CA
Is there a way to load the return of system into a variable?

e.g.

sysreturn = system("ls -l |wc -l")

thank you.
 
thank you for the quick reply. I tried the search but I was searching for the wrong command.

thank you
 
sorry but that didn't work, all it returned is the content of the '' not the number of lines. am I missing something?

thanks
 
A kinda dodgy approach I used to use is to open a filehandle, select it, then do the system commands.

Kinda along the lines of...

open (CAPTOR, ">./output.txt");
select CAPTOR;
system ("commands");
select STDOUT;
close (CAPTOR);

And then open output.txt for reading.
 
Code:
my @stuff = qx[ls -l];
print scalar @stuff;
In this instance you don't need the wc -l because the number of files is the count of items in the @stuff array. I tend to prefer qx[...] to backticks, it's just easier to read...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top