Subject: Re: Redirecting STDOUT
Yes, it definitely could be. I had the same problem once and fixed it by upgrading to 5.8 -Matt >I've had the same problem using qx too. Could it be that I'm using PERL >5.6? >Chris ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
>Hi everyone, >I saw the following on another PERL list-serve: >"If you are on windows, then see perlfaq8 if ActiveState perl for >how to redirect STDOUT and STDERR when doing backticks." >I'd like to be able to capture STDOUT as a string. But nothing on perlfaq8 struck me as relevant. Did I miss >something? How do I do this? I frequently get drastic errors (my computer shuts down!) when I try to use backticks. and I replied: I do this in nearly all of my perl scripts - at least once. Here'some code. my $status = `dir 2>&1`; Output (Stdout & Stderr) are both captured in the $status variable. Hope this helps, (and I hope that's what you were asking) And Chris answered: >Hi Martin, >Thanks. >The output from what is captured? The output from the "dir" command. > Let me elaborate on what I'm trying to do. I'd like to test if certain scripts have syntax errors. But if I do >my $return = `perl -c $progname 2>&1`; >the computer crashes. Ahhh.look at what you're trying to do here. You're launching an instance of perl by running the script which has the above code. Then, in your code, you're launching another instance of perl.exe. I suspect that this is what is crashing the machine...BUT... I took your code and tested it and it ran fine. Methinks there is some other instability on your machine or in your code. Maybe uninstall Perl and re-install? Maybe try to determine where exactly in the script it crashes? Might not be crashing on that command at all... -mm -- Martin A. Miller Walgreens Integration Architecture Group (AKA StdCfg) 847-914-5138 You can't accuse me of anything I haven't already confessed to. -- Keith Richards ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Chris Rodriguez wrote: > > > */Bill Luebkert <[EMAIL PROTECTED]>/* wrote: > > Chris Rodriguez wrote: > > Hi everyone, > > I saw the following on another PERL list-serve: > > > > "If you are on windows, then see perlfaq8 if ActiveState perl for > > how to redirect STDOUT and STDERR when doing backticks." > > > > I'd like to be able to capture STDOUT as a string. But nothing on > perlfaq8 struck me as relevant. Did I miss something? How do I do > this? I frequently get drastic errors (my computer shuts down!) when > I try to use backticks. > > Did you read: > > How can I capture STDERR from an external command? > > Also check out the perlop man page under: > > qx/STRING/ > `STRING` > > ... > > $output = `cmd`; > # or grab STDERR as well > $output = `cmd 2>&1`; > > Hi. "cmd" refers to any command, right? Neither formulation works for > me. If I do: > $output = `perl -c somescript.pl`; > I see "somescript.pl syntax OK" on the screen, and the variable $output > remains unassigned. If I do: > $output = `perl -c somescript.pl 2>&1`; > I get a message saying "This program has performed an illegal > operation..." and I have to turn off my computer. > I've had the same problem using qx too. Could it be that I'm using PERL > 5.6? > first, this sounds realy bad if you have to reboot your computer after running such simple perl things. Maybe you should check your installation of perl and windows, and maybe your RAM too. Anyway, I use to write the output in a filehandle like this open IN, "change user /query 2>&1|" or warn "does not work\n"; change user /query is a command from a Windows Terminal Server. always worked for me. Alex Vorstand/Board of Management: Dr. Bernd Finkbeiner, Dr. Florian Geyer, Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech Vorsitzender des Aufsichtsrats/ Chairman of the Supervisory Board: Prof. Dr. Hanns Ruder Sitz/Registered Office: Tuebingen Registergericht/Registration Court: Stuttgart Registernummer/Commercial Register No. HRB 382196 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Chris Rodriguez wrote: > > Hi. "cmd" refers to any command, right? Neither formulation works for > me. If I do: > $output = `perl -c somescript.pl`; > I see "somescript.pl syntax OK" on the screen, and the variable $output > remains unassigned. If I do: > $output = `perl -c somescript.pl 2>&1`; > I get a message saying "This program has performed an illegal > operation..." and I have to turn off my computer. > I've had the same problem using qx too. Could it be that I'm using PERL > 5.6? Could be, but I think it should still work. Why haven't you upgraded ? I assume you're running from a console window using cmd.exe shell ? ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Hi *! Nelson R. Pardee wrote: > Chris, > > Do you absolutely need backticks? You can invoke a command/program and > capture stdin, stdout with OPEN2, and stderr with OPEN3. I haven't done it > in ActivePerl although I have in Unix. I do know they don't work well for > my purposes with another perl script, but they might work with a system > command or standard program. > > On Sun, 1 Apr 2007, Chris Rodriguez wrote: > >> Bill Luebkert <[EMAIL PROTECTED]> wrote: Chris Rodriguez wrote: >>> Hi everyone, >>> I saw the following on another PERL list-serve: >>> >>> "If you are on windows, then see perlfaq8 if ActiveState perl for >>> how to redirect STDOUT and STDERR when doing backticks." >>> >>> I'd like to be able to capture STDOUT as a string. But nothing on >>> perlfaq8 struck me as relevant. Did I miss something? How do I do >>> this? I frequently get drastic errors (my computer shuts down!) when >>> I try to use backticks. maybe not the smartes way of doing it, but that's what I use for capturing STDOUT/STDERR $LogFile = 'C:/Programme/Serv-Int-Programme/scwin_log.txt'; open _LOG, "+>>$LogFile" or warn "cannot open $LogFile!\n"; *STDOUT = *_LOG; *STDERR = *_LOG; Alex ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Chris, Do you absolutely need backticks? You can invoke a command/program and capture stdin, stdout with OPEN2, and stderr with OPEN3. I haven't done it in ActivePerl although I have in Unix. I do know they don't work well for my purposes with another perl script, but they might work with a system command or standard program. On Sun, 1 Apr 2007, Chris Rodriguez wrote: > Bill Luebkert <[EMAIL PROTECTED]> wrote: Chris Rodriguez wrote: > > Hi everyone, > > I saw the following on another PERL list-serve: > > > > "If you are on windows, then see perlfaq8 if ActiveState perl for > > how to redirect STDOUT and STDERR when doing backticks." > > > > I'd like to be able to capture STDOUT as a string. But nothing on > > perlfaq8 struck me as relevant. Did I miss something? How do I do > > this? I frequently get drastic errors (my computer shuts down!) when > > I try to use backticks. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Bill Luebkert <[EMAIL PROTECTED]> wrote: Chris Rodriguez wrote: > Hi everyone, > I saw the following on another PERL list-serve: > > "If you are on windows, then see perlfaq8 if ActiveState perl for > how to redirect STDOUT and STDERR when doing backticks." > > I'd like to be able to capture STDOUT as a string. But nothing on perlfaq8 > struck me as relevant. Did I miss something? How do I do this? I frequently > get drastic errors (my computer shuts down!) when I try to use backticks. Did you read: How can I capture STDERR from an external command? Also check out the perlop man page under: qx/STRING/ `STRING` ... $output = `cmd`; # or grab STDERR as well $output = `cmd 2>&1`; Hi. "cmd" refers to any command, right? Neither formulation works for me. If I do: $output = `perl -c somescript.pl`; I see "somescript.pl syntax OK" on the screen, and the variable $output remains unassigned. If I do: $output = `perl -c somescript.pl 2>&1`; I get a message saying "This program has performed an illegal operation..." and I have to turn off my computer. I've had the same problem using qx too. Could it be that I'm using PERL 5.6? Chris - Never miss an email again! Yahoo! Toolbar alerts you the instant new Mail arrives. Check it out.___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Chris Rodriguez wrote: > Hi everyone, > I saw the following on another PERL list-serve: > > "If you are on windows, then see perlfaq8 if ActiveState perl for > how to redirect STDOUT and STDERR when doing backticks." > > I'd like to be able to capture STDOUT as a string. But nothing on perlfaq8 > struck me as relevant. Did I miss something? How do I do this? I > frequently get drastic errors (my computer shuts down!) when I try to use > backticks. Did you read: How can I capture STDERR from an external command? Also check out the perlop man page under: qx/STRING/ `STRING` ... $output = `cmd`; # or grab STDERR as well $output = `cmd 2>&1`; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT from open.
Hi Bill, I don't think its a threading issue. when i comment out the threads, it still prints to STDOUT even when there is no print statement. eg. here is the piece of code. open(RH,"|$cmd|"); <--- all i am doing is instantiating a process, why is it printing to STDOUT, when i have not told it to?? # my $inT = threads->create(\&input,RH,$client); # threads are commented out. # my $outT = threads->create(\&output,RH,$client); Thanks in advance for any help Regards Jeremy A. At 01:08 AM 12/13/2003, you wrote: Jeremy A wrote: > Hi again, > > I have changed my server solution to use perl 5.8 threads, instead of fork. > It is set up for non-blocking sockets. It has a client that is non-blocking > as well. > my problem is that It still prints to STDOUT, not $client. > > Your help is appreciated. Thanks in advance. > > Regards, > > Jeremy Aiyaduria. > > below is the code. I can't help with 5.8 code since I'm still on 5.6 (I don't have threads or fork). -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT, help please
Hi again, I have changed my server solution to use perl 5.8 threads, instead of fork. It is set up for non-blocking sockets. It has a client that is non-blocking as well. my problem is that It still prints to STDOUT, not $client. Your help is appreciated. Thanks in advance. Regards, Jeremy Aiyadurai. below is the code. -- use IO::Socket; use IPC::Open2; use threads; #$| = 1; my $PORT = 8887; # pick something not in use my $server; my $kidpid; my $SDIR = getcwd(); print "$SDIR"; serverproc(); sub serverproc { $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen=> SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; #while(1) #{ while ($client = $server->accept()) { #$client->autoflush(1); $hostinfo = gethostbyaddr($client,$client->peeraddr); my $cmd = <$client>; open(RH,"|$cmd|"); my $inT = threads->create(\&input,RH,$client); my $outT = threads->create(\&output,RH,$client); } } sub input($$) { ($WRITEHANDLE,$client) = @_; my $byte; while (defined(my $byte = <$client>)) { print $WRITEHANDLE $byte; } } sub output($$) { ($READHANDLE,$client) = @_; my $l; while ((defined ($l = <$READHANDLE>))) { $client->send($l); <-- data not sent to $client, it is sent to STDOUT , dont know why??? } } Jeremy A wrote: > Hi all, > > I am using IPC::Open2. I have a Read Handle (RH) and a Write Handle (WH). I > fork() for doing non-blocking IO. > my problem is , when i try the print the RH to socket ($client), It writes > to STDOUT (server console screen). nothing gets written to the socket. > > Thanks in advance for any help on this. > > Regards, > > Jeremy Aiyadurai. > > The following is the code. > > > $server = IO::Socket::INET->new( Proto => 'tcp', >LocalPort => $PORT, >Listen=> SOMAXCONN, >Reuse => 1); > > > die "can't setup server" unless $server; > print "[Server $0 accepting clients]\n"; > #while(1) > #{ > > while ($client = $server->accept()) { > $client->autoflush(1); > my $LFLAG = 0; > my $UP; > $hostinfo = gethostbyaddr($client,$client->peeraddr); > my $cmd = <$client>; >open2(\*RH,\*WH,"$cmd"); open2 \*WH, \*RH, $cmd; > die "can't fork: $!" unless defined($kidpid = fork()); There could be problems with forking on Win32. > if ($kidpid) { > my $byte; > while (defined(my $byte = <$client>)) { > print WH $byte; > } > #kill("TERM", $kidpid); > } > else { > my $l; > while ((defined ($l = ))) { <- problem here, RH does not write > to client, it writes to STDOUT. > print $client $l; > } > > } > } -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Hi again, I have changed my server solution to use perl 5.8 threads, instead of fork. It is set up for non-blocking sockets. It has a client that is non-blocking as well. my problem is that It still prints to STDOUT, not $client. Your help is appreciated. Thanks in advance. Regards, Jeremy Aiyaduria. below is the code. -- use IO::Socket; use IPC::Open2; use threads; #$| = 1; my $PORT = 8887; # pick something not in use my $server; my $kidpid; my $SDIR = getcwd(); print "$SDIR"; serverproc(); sub serverproc { $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen=> SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; #while(1) #{ while ($client = $server->accept()) { #$client->autoflush(1); $hostinfo = gethostbyaddr($client,$client->peeraddr); my $cmd = <$client>; open(RH,"|$cmd|"); my $inT = threads->create(\&input,RH,$client); my $outT = threads->create(\&input,RH,$client); } } sub input($$) { ($WRITEHANDLE,$client) = @_; my $byte; while (defined(my $byte = <$client>)) { print $WRITEHANDLE $byte; } } sub output($$) { ($READHANDLE,$client) = @_; my $l; while ((defined ($l = <$READHANDLE>))) { $client->send($l); <-- data not sent to $client, it is sent to STDOUT , dont know why??? } } Jeremy A wrote: > Hi all, > > I am using IPC::Open2. I have a Read Handle (RH) and a Write Handle (WH). I > fork() for doing non-blocking IO. > my problem is , when i try the print the RH to socket ($client), It writes > to STDOUT (server console screen). nothing gets written to the socket. > > Thanks in advance for any help on this. > > Regards, > > Jeremy Aiyadurai. > > The following is the code. > > > $server = IO::Socket::INET->new( Proto => 'tcp', >LocalPort => $PORT, >Listen=> SOMAXCONN, >Reuse => 1); > > > die "can't setup server" unless $server; > print "[Server $0 accepting clients]\n"; > #while(1) > #{ > > while ($client = $server->accept()) { > $client->autoflush(1); > my $LFLAG = 0; > my $UP; > $hostinfo = gethostbyaddr($client,$client->peeraddr); > my $cmd = <$client>; >open2(\*RH,\*WH,"$cmd"); open2 \*WH, \*RH, $cmd; > die "can't fork: $!" unless defined($kidpid = fork()); There could be problems with forking on Win32. > if ($kidpid) { > my $byte; > while (defined(my $byte = <$client>)) { > print WH $byte; > } > #kill("TERM", $kidpid); > } > else { > my $l; > while ((defined ($l = ))) { <- problem here, RH does not write > to client, it writes to STDOUT. > print $client $l; > } > > } > } -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Redirecting STDOUT
Jeremy A wrote: > Hi all, > > I am using IPC::Open2. I have a Read Handle (RH) and a Write Handle (WH). I > fork() for doing non-blocking IO. > my problem is , when i try the print the RH to socket ($client), It writes > to STDOUT (server console screen). nothing gets written to the socket. > > Thanks in advance for any help on this. > > Regards, > > Jeremy Aiyadurai. > > The following is the code. > > > $server = IO::Socket::INET->new( Proto => 'tcp', >LocalPort => $PORT, >Listen=> SOMAXCONN, >Reuse => 1); > > > die "can't setup server" unless $server; > print "[Server $0 accepting clients]\n"; > #while(1) > #{ > > while ($client = $server->accept()) { > $client->autoflush(1); > my $LFLAG = 0; > my $UP; > $hostinfo = gethostbyaddr($client,$client->peeraddr); > my $cmd = <$client>; >open2(\*RH,\*WH,"$cmd"); open2 \*WH, \*RH, $cmd; > die "can't fork: $!" unless defined($kidpid = fork()); There could be problems with forking on Win32. > if ($kidpid) { > my $byte; > while (defined(my $byte = <$client>)) { > print WH $byte; > } > #kill("TERM", $kidpid); > } > else { > my $l; > while ((defined ($l = ))) { <- problem here, RH does not write > to client, it writes to STDOUT. > print $client $l; > } > > } > } -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: redirecting stdout from the dos command line.
> > H:\> test.pl > test.out NT doesn't allow command line redirection such as >, >>, or | unless the executable file extension is .BAT, .CMD, .COM, or .EXE. perl test.pl > test.out should work because perl is an .EXE file. Merrill ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Redirecting STDOUT
On Wed, 28 Mar 2001, Edwards, Mark (CXO) wrote: > Does anyone know of a way to redirect STDOUT to a variable? If I call a > subroutine from a module that prints a message to the screen, I want to > suppress the output and capture it in a scalar or array. > > Any ideas?? > Redirection is a one-time event that happens before or at the time a file is opened you can't redirect STDOUT to a varaiable only when STDOUT is used in a subroutine. You can change the redirection while the file is open. [EMAIL PROTECTED] All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users