Pawan wrote:

> I have been trying to capture the output of a shell command (say
> ls or echo *) in a variable but all i have been able to capture
> is the return status of system comman which is 0.
>
> I also tried changing the defaulT output handler from STDOUT to
> the filehandle of a file I have created hoping tha the optput of
> my shell command will be captured by the new filehandler but all
> in vain.
>
> This problem is killing me.
>
> Please help.

Hi Pawan.

What you need is backtick quotes:

  `ls`

or

  qx(ls)

which is the same thing. It does the same as system in that it
executes a shell command, but instead of the exit status it
returns the text that the command output to its STDOUT. In list
context the return value will be a list of lines (still with
their trailing newlines) and in scalar context it will be a
single scalar value containing all of the output.

Be careful though: it's usually better to write Perl code
than to rely on the output from an an external utility.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to