Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 2872

Show
Ignore:
Timestamp:
11/13/07 09:59:16 (1 year ago)
Author:
jcomellas
Message:

Fix for ticket #715: we now allow users to read from the Process pipes after
the process has died, whether by means of a call to kill() or to wait().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/sys/Process.d

    r2870 r2872  
    255255    public ~this() 
    256256    { 
    257         clean(); 
     257        _running = false; 
     258        cleanPipes(); 
    258259    } 
    259260 
     
    418419     * 
    419420     * Remarks: 
    420      * The process must be running before calling this method. 
     421     * The stream will be null if no child process has been executed. 
    421422     */ 
    422423    public OutputStream stdin() 
    423     in 
    424     { 
    425         assert(_running); 
    426     } 
    427     body 
    428424    { 
    429425        return _stdin; 
     
    437433     * 
    438434     * Remarks: 
    439      * The process must be running before calling this method. 
     435     * The stream will be null if no child process has been executed. 
    440436     */ 
    441437    public InputStream stdout() 
    442     in 
    443     { 
    444         assert(_running); 
    445     } 
    446     body 
    447438    { 
    448439        return _stdout; 
     
    456447     * 
    457448     * Remarks: 
    458      * The process must be running before calling this method. 
     449     * The stream will be null if no child process has been executed. 
    459450     */ 
    460451    public InputStream stderr() 
    461     in 
    462     { 
    463         assert(_running); 
    464     } 
    465     body 
    466452    { 
    467453        return _stderr; 
     
    616602            SECURITY_ATTRIBUTES sa; 
    617603            STARTUPINFO         startup; 
     604 
     605            // We close and delete the pipes that could have been left open 
     606            // from a previous execution. 
     607            cleanPipes(); 
    618608 
    619609            // Set up the security attributes struct. 
     
    679669        else version (Posix) 
    680670        { 
     671            // We close and delete the pipes that could have been left open 
     672            // from a previous execution. 
     673            cleanPipes(); 
     674 
    681675            Pipe pin = new Pipe(DefaultStdinBufferSize); 
    682676            Pipe pout = new Pipe(DefaultStdoutBufferSize); 
     
    864858                assert(_info !is null); 
    865859 
    866                 // We clean up once we're done waiting for the process to finish. 
     860                // We clean up the process related data and set the _running 
     861                // flag to false once we're done waiting for the process to 
     862                // finish. 
     863                // 
     864                // IMPORTANT: we don't delete the open pipes so that the parent 
     865                //            process can get whatever the child process left on 
     866                //            these pipes before dying. 
    867867                scope(exit) 
    868868                { 
    869869                    CloseHandle(_info.hProcess); 
    870                     clean()
     870                    _running = false
    871871                } 
    872872 
     
    911911            { 
    912912                int rc; 
     913 
     914                // We clean up the process related data and set the _running 
     915                // flag to false once we're done waiting for the process to 
     916                // finish. 
     917                // 
     918                // IMPORTANT: we don't delete the open pipes so that the parent 
     919                //            process can get whatever the child process left on 
     920                //            these pipes before dying. 
     921                scope(exit) 
     922                { 
     923                    _running = false; 
     924                } 
    913925 
    914926                // Wait for child process to end. 
     
    979991                                        _args[0], _pid, result.status, SysError.lastMsg); 
    980992                } 
    981                 clean(); 
    982993            } 
    983994            else 
     
    10221033                    assert(_info !is null); 
    10231034 
     1035                    // We clean up the process related data and set the _running 
     1036                    // flag to false once we're done waiting for the process to 
     1037                    // finish. 
     1038                    // 
     1039                    // IMPORTANT: we don't delete the open pipes so that the parent 
     1040                    //            process can get whatever the child process left on 
     1041                    //            these pipes before dying. 
    10241042                    scope(exit) 
    10251043                    { 
    10261044                        CloseHandle(_info.hProcess); 
    1027                         clean()
     1045                        _running = false
    10281046                    } 
    10291047 
     
    10571075                if (.kill(_pid, SIGTERM) != -1) 
    10581076                { 
     1077                    // We clean up the process related data and set the _running 
     1078                    // flag to false once we're done waiting for the process to 
     1079                    // finish. 
     1080                    // 
     1081                    // IMPORTANT: we don't delete the open pipes so that the parent 
     1082                    //            process can get whatever the child process left on 
     1083                    //            these pipes before dying. 
    10591084                    scope(exit) 
    1060                         clean(); 
     1085                    { 
     1086                        _running = false; 
     1087                    } 
    10611088 
    10621089                    // FIXME: is this loop really needed? 
     
    12271254 
    12281255    /** 
    1229      * Reset the object to its initial state. 
    1230      */ 
    1231     protected void clean() 
    1232     { 
    1233         _running = false; 
     1256     * Close and delete any pipe that may have been left open in a previous 
     1257     * execution of a child process. 
     1258    */ 
     1259    protected void cleanPipes() 
     1260    { 
    12341261        delete _stdin; 
    12351262        delete _stdout;