D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] emulating ttys in perl



On Mon, Apr 14, 2003 at 11:18:31AM +0100, Jamie Andrews wrote:

> I don't agree, backticks or qx() capture both stderr and stdout

I'm afraid that's not actually true.

> bash-2.05a$ ls -l foo
> ls: foo: No such file or directory
> bash-2.05a$ ls -l foo 2>/dev/null
> bash-2.05a$ perl -e 'print qx(ls -l foo);'
> ls: foo: No such file or directory

That's just printing to stderr and going around he perl script, as
described.

try:

test.pl

#!/usr/bin/perl

print STDOUT "stdout\n";
print STDERR "stderr\n";

test2.pl

#!/usr/bin/perl

$string = uc(`test.pl`);

print "$string\n";

$string = uc(qx(test.pl));

print "$string\n";

... and now try:

#!/usr/bin/perl

$string = uc(`test.pl 2>&1`);

print "$string\n";

$string = uc(qx(test.pl 2>&1));

print "$string\n";

... which cathes both and ...

#!/usr/bin/perl

$string = uc(`test.pl 2>/dev/null`);

print "$string\n";

$string = uc(qx(test.pl 2>/dev/null));

print "$string\n";

... which ditches STDERR.

Cheers

Steve




--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly