PDA

View Full Version : Shell command then capture output


samuurai
03-17-2008, 05:58 PM
Hi,

I'm new to perl and i'm writing a simple backup script.

I want to supply the script with a top-level directory, then have it iterate through the directories and backing each one up individually.

How do I execute a shell command then capture the results into an array?

I know the shell command, I just need to know the programming side.

Any clues?

Thanks!
Beren

FishMonger
03-17-2008, 06:17 PM
You use `` backticks to retrieve the output of a shell command.
example:
my @array = `ls`;However, you may want to look at using some of Perl's methods instead of forking a shell call.

samuurai
03-17-2008, 10:10 PM
You use `` backticks to retrieve the output of a shell command.
example:
my @array = `ls`;However, you may want to look at using some of Perl's methods instead of forking a shell call.

Oh, cool so it has similar functionality to bash using the "`" quotes.

Thanks!

Alright, i'll take a look at the methods.. I didn't realise it could do that. Cheers!

Beren