Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: IPC::Open3 misbehaving when STDOUT is not FD #1

by Khen1950fx (Canon)
on Jun 07, 2009 at 00:43 UTC ( [id://769198]=note: print w/replies, xml ) Need Help??


in reply to IPC::Open3 misbehaving when STDOUT is not FD #1

Admittedly, my first response was on the fly, but I dug deeper and tried this:

#!/usr/bin/perl use strict; use warnings; use diagnostics; use IPC::Open3; use POSIX 'setsid'; sub daemonize { chdir '/' or die "Can't chdir to /: $!"; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; defined( my $pid = fork ) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; } open( SAVE_STDOUT, ">&", STDOUT ) or die "save stdout failed"; open( DEVNULL, "< /dev/null" ) or die "open /dev/null failed"; open( FH1, "> /dev/null" ) or die "Open /dev/null failed"; &daemonize( *FH1 ); open3( *DEVNULL, *PIPE, undef, "/bin/sh", "-c", <<EOF ); printf "out 1\\nout 2\\nout 3\\n" printf "err 1\\nerr 2\\nerr 3\\n" >&2 EOF ; open( STDOUT, ">&", *SAVE_STDOUT ) or die "restore stdout failed: $!"; while(<PIPE>) { print "PIPE: ", $_; } close(PIPE) or die "close pipe failed"; exit(1);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://769198]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found