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

Running other programs from perl using `someprogram`

Status
Not open for further replies.

LucL

Programmer
Jan 23, 2006
117
0
0
US
Ok,

So something like my @mfiles=`ls` will run the LS command and populate mfiles array with the files.

But for some reason when I run a different command the other linux application always outputs to the screen and I cannot capture it using $t1=`linuxprogram`

Is there any way to run and capture the output of a program into a perl variable? I know there must be a fairly simple way but I can't figure it out. The output is just a few lines of text but with this program it always goes to the screen.

Thanks!
Luc L.
 
It *may* be that the program is writing to stderr, so you can try this:
Code:
$t1=`linuxprogram 2>&1`

alternatively, you can use a pipe to do this, like:
Code:
open(X, "linuxprogram 2>&1 |"); 
print while (<X>);
close(X);

---
cheers!
san
smoking3vc.gif


print length "The answer to life, universe & everything!
 
genius. thanks that worked like a charm!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top