开发者

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

开发者 https://www.devze.com 2023-02-04 03:49 出处:网络
I have a perl script that I can pass arguments to from the command line and it will output the 开发者_如何学Pythonresults. I have tried to capture those results:

I have a perl script that I can pass arguments to from the command line and it will output the 开发者_如何学Pythonresults. 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?


The command probably outputs to stderr, not stdout. Try

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


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.


Use this

@systemReturn = `$cmd`;
0

精彩评论

暂无评论...
验证码 换一张
取 消