Changeset 710

Show
Ignore:
Timestamp:
07/27/07 00:53:12 (1 year ago)
Author:
Gregor
Message:

dsssps/process.d: Running processes no longer blocks DPS.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • other/dps/trunk/dsssps/process.d

    r708 r710  
    11module dsssps.process; 
     2 
     3import tango.io.Console; 
     4import tango.io.model.IConduit; 
    25 
    36import tango.sys.Environment; 
    47import tango.sys.Process; 
    58 
    6 import tango.text.stream.LineIterator; 
    7  
    89// FIXME: Windows? 
    9 import tango.stdc.posix.sys.wait; 
     10version (Posix) { 
     11    import tango.stdc.posix.fcntl; 
     12    import tango.stdc.posix.sys.wait; 
     13
    1014 
    1115import wx.wx; 
     
    1620class DPSProcessWindow : wxTextCtrl { 
    1721    Process proc; 
    18     LineIterator!(char) li; 
    1922    bool fin = false; 
    2023 
     
    2427        proc = new Process(cmd, Environment.get()); 
    2528        proc.execute(); 
    26         li = new LineIterator!(char)(proc.stdout); 
     29 
     30        // make it nonblocking if possible 
     31        version (Posix) { 
     32            fcntl(proc.stdout.fileHandle(), F_SETFL, 
     33                fcntl(proc.stdout.fileHandle(), F_GETFL) | O_NONBLOCK); 
     34        } else { 
     35            static assert(0); 
     36        } 
    2737 
    2838        // set up the text area 
     
    3848 
    3949        // check for new input [FIXME] 
    40         if (proc.isRunning()) { 
    41             foreach (line; li) { 
    42                 AppendText(line ~ "\n"); 
    43                 (cast(wxIdleEvent) e).RequestMore(); 
    44                 return; 
     50        char[1024] buf; 
     51        uint rd; 
     52 
     53        try { 
     54            rd = proc.stdout.input.read(buf); 
     55            if (rd != IConduit.Eof) { 
     56                AppendText(buf[0..rd]); 
    4557            } 
     58        } catch (Exception e) {} // ignore errors 
     59        (cast(wxIdleEvent) e).RequestMore(); 
    4660 
    47             // done, mark so 
    48             fin = true; 
    49             AppendText("\n\nProgram terminated.\n\nSTDERR:\n"); 
     61        // check if we're done 
     62        if (waitpid(proc.pid, null, WNOHANG) != proc.pid) { 
     63            return; 
     64        } 
    5065 
    51             foreach (line; new LineIterator!(char)(proc.stderr)) { 
    52                 AppendText(line ~ "\n"); 
     66        // done, mark so 
     67        fin = true; 
     68        AppendText("\n\nProgram terminated.\n\nSTDERR:\n"); 
     69 
     70        // now get stderr 
     71        try { 
     72            while ((rd = proc.stderr.input.read(buf)) > 0) { 
     73                AppendText(buf[0..rd]); 
    5374            } 
    54         } 
     75        } catch (Exception e) {} // ignore errors 
    5576    } 
    5677}