Ok, I give up.

Here's a little script that attempts to spawn child processes (using
Win32::Process) and capture the output from them.

### cut here ###

#perl -w
use Win32::Process;
use IO::File;

my $loopcount = 0;
while( 1 ) {
    ## Save existing
    open SAVEOUT, ">&STDOUT";
    open SAVEERR, ">&STDERR";

    ## Create new
    my $stdout = IO::File::new_tmpfile();
    my $stderr = IO::File::new_tmpfile();

    ## Establish new as default
    open STDOUT, ">&=" . $stdout->fileno();
    open STDERR, ">&=" . $stderr->fileno();

    ## Unbuffer
    select((select(STDERR), $| = 1)[0]);
    select((select(STDOUT), $| = 1)[0]);

    ## Spawn
    my $process;
    Win32::Process::Create( $process,
                            "$ENV{ SystemRoot }\\system32\\cmd.exe", 
                            "cmd /c dir",
                            1,
                            NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED,
                            $ENV{ SystemRoot } ) or die( "Splat" );

    ## Restore original streams
    open STDOUT, ">&SAVEOUT";
    open STDERR, ">&SAVEERR";

    ## Activate process
    $process->Resume();
    $process->Wait(INFINITE);

    print $loopcount++, "\n";
}

### cut here ###

The script runs well for about 248-250 iterations and then everything
goes bad.
Specifically, the output streams seem to become entangled, crossed
and/or
just plain mis-associated.  For example, I see the following on my
console:

0
1
2
3
.
.
246
247
248
249
 Volume in drive C has no label.
 Volume Serial Number is ACA4-6811

 Directory of C:\WINDOWS

11-Feb-02  15:12    <DIR>          .
11-Feb-02  15:12    <DIR>          ..
01-Feb-02  12:16                 0 0.log
13-Dec-01  08:41    <DIR>          addins
13-Dec-01  21:34    <DIR>          AppPatch
11-Feb-02  13:32               256 cdplayer.ini
23-Aug-01  05:00            82,944 clock.avi
08-Jan-02  13:09            27,618 comsetup.log
13-Dec-01  08:41    <DIR>          Config
13-Dec-01  08:41    <DIR>          Connection Wizard
13-Dec-01  20:17                 0 control.ini
13-Dec-01  22:10    <DIR>          Cursors
01-Feb-02  12:16    <DIR>          Debug
23-Aug-01  05:00                 2 desktop.ini
13-Dec-01  21:09    <DIR>          Downloaded Installations

etc ...

This continues with each iteration of the loop (until I kill it).

I'm thoroughly confused here.  I can only suspect a bug in one (or more)
of Win32::Process, perl or the actual Win32 CreateProcess interface.

Anyone have any suggestions as to how I can narrow down the problem?

During execution (according to the task manager) the perl process
never exceeds ~3.5MB of memory (real and virtual) and only has ~25
handles outstanding (thus, I don't think I'm leaking resources).

Thanks,

-- Robert Trace

----
System info:

ActivePerl 5.6.1 Build 631 (happened on 629 too)
Windows XP Professional (also occurs on NT4+SP6a)
768MB RAM
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to