John
John

Reputation: 1540

how do you capture multiline output from a perl `command` call?

I have a perl script that I can pass arguments to from the command line and it will output the results. I have tried to capture those results:

$systemReturn = `$cmd`;

with only a response of an empty string. I know this file outputs a multi-line string. Obvously there is a diffirent method needed to capture it. Does anyone know how I would get this done?

Upvotes: 3

Views: 4022

Answers (3)

Ashley
Ashley

Reputation: 4335

I would recommend checking up on Capture::Tiny or IO::CaptureOutput as well. It makes it easier and more portable to catch the output, split or join STDOUT and STDERR, check for success, and even tee.

Upvotes: 2

ysth
ysth

Reputation: 98398

The command probably outputs to stderr, not stdout. Try

$systemReturn = `$cmd 2>&1`;

Upvotes: 5

jRJ
jRJ

Reputation: 278

Use this

@systemReturn = `$cmd`;

Upvotes: 0

Related Questions