finaly found a souloution that works its a bit different from my first approch but it works (in fact the solution is to use a socket and to "poll" the socket yourself ....) something like this :
#!/urs/bin/perl -w use strict; use warnings; use IO::Socket; use Tk; use subs qw/read_sock/; my $mw; my $sel; my $sock; my $text; my $line; my $scriptname = "my_script.pl"; #some Tk $mw = MainWindow->new(); $text = $mw->Text->pack; my $goButton = $mw->Button( -text=> "Accept", -command => \&go )->pack( -side=>"left", ); #"polling" socket $mw->repeat(50 => \&read_sock); MainLoop; sub read_sock{ return unless $sock; my $hand = $sock; my @ready = $sel->can_read(0); return if $#ready == -1; $hand = $ready[0]; my $numbytes = 1; my $buf; sysread $hand, $buf, $numbytes; print "read a $buf\n"; $line .= $buf; if ($buf eq "\n"){ if ($line eq "EOF\n"){ undef $sel; undef $sock; undef $line; return; } $text->insert('end',"$line"); undef $line; } } sub go{ my $ProcessObj; require Win32; require Win32::Process; Win32::Process::Create($ProcessObj, "c:\\perl\\bin\\perl.exe", "perl $scriptname", 0, 0, ".")|| die ErrorReport(); sleep 2; # let the script time to built the socket $sock = IO::Socket::INET->new(PeerAddr=> 'localhost:13579'); die "cannot connect: $!\n" unless defined $sock; use IO::Select; $sel = IO::Select->new(); $sel->add($sock); }
and in $scriptname
#!/usr/bin/perl -w use IO::Socket; use strict; my $socket = IO::Socket::INET->new( Listen => 5, Reuse => 1, LocalPort => 13579, Proto => 'tcp', )||die "couldn't open socket : $!\n"; my $new_socket = $socket -> accept(); #so far so good #if the is $something_to_say syswrite $new_socket, "$something_to_say\n";
and to sigal the end to the parent (since there is no sigchld when using Win32::Process)
END{ syswrite $new_socket, "EOF\n"; }

----
NaSe
:x


In reply to Re: Win32 fork using open3 by NaSe77
in thread Win32 fork using open3 by NaSe77

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.