Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

capturing stderr into a variable...

6 views
Skip to first unread message

Johanes Suhardjo

unread,
Jun 1, 1994, 11:06:58 AM6/1/94
to
Johanes Suhardjo (joh...@farida.cc.nd.edu) wrote:
> select(NS); # NS is the socket to communicate with "client"
> while (<NS>) {
> # print "$con: $_";
> $output = `$_ 2>&1`; # Somehow STDERR doesn't go to $output.
> print "hahaha: $output hihihi:\n";
> }

Silly me! Before everybody decide to embarrass me, here is my stupid
mistake: a line is passed from "client" complete with its newline
character. Putting a "chop;" statement before $output solves my
problem. As usual, a question has to be asked before I can find the
answer myself.

--
Johanes Suhardjo (joh...@farida.cc.nd.edu)
--
Drive defensively. Buy a tank.

Johanes Suhardjo

unread,
May 31, 1994, 2:45:58 PM5/31/94
to
Tim McDaniel (mcda...@convex.com) wrote:
> FAQ question 2.24: "How can I capture STDERR from an external command?".

I tried
$command = 'touch /test';
$output = `$command 2>&1`;


print "hahaha: $output hihihi:\n";

it gave me
hahaha: touch: cannot create /test: Permission denied
hihihi:
which was okay.

Now if I pass the command through a socket (pp. 342-345 Camel book),
it doesn't redirect STDERR to $output.
For example
in "server":


select(NS); # NS is the socket to communicate with "client"
while (<NS>) {
# print "$con: $_";
$output = `$_ 2>&1`; # Somehow STDERR doesn't go to $output.
print "hahaha: $output hihihi:\n";
}

when I typed
touch /test
in "client", the output on "client" window was:
hahaha: hihihi:
while the error message
touch: cannot create /test: Permission denied
was displayed on "server" window.

Can somebody tell me why? Thanks.

--
Johanes Suhardjo (joh...@farida.cc.nd.edu)
--

Antonym, n.:
The opposite of the word you're trying to think of.

Larry Wall

unread,
Jun 1, 1994, 5:29:01 PM6/1/94
to
In article <2sg0l6$5...@news.nd.edu> joh...@farida.cc.nd.edu (Johanes Suhardjo) writes:
: while (<NS>) {
: $output = `$_ 2>&1`; # Somehow STDERR doesn't go to $output.

You need to chop the newline on $_ before using it in a command. The
newline turns it into two commands, the second of which doesn't do much.
(When reading from a socket connected to Who Knows What, bear in mind you
might also have to chop a carriage return.)

Larry

0 new messages