Changeset 710
- Timestamp:
- 07/27/07 00:53:12 (1 year ago)
- Files:
-
- other/dps/trunk/dsssps/process.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
other/dps/trunk/dsssps/process.d
r708 r710 1 1 module dsssps.process; 2 3 import tango.io.Console; 4 import tango.io.model.IConduit; 2 5 3 6 import tango.sys.Environment; 4 7 import tango.sys.Process; 5 8 6 import tango.text.stream.LineIterator;7 8 9 // FIXME: Windows? 9 import tango.stdc.posix.sys.wait; 10 version (Posix) { 11 import tango.stdc.posix.fcntl; 12 import tango.stdc.posix.sys.wait; 13 } 10 14 11 15 import wx.wx; … … 16 20 class DPSProcessWindow : wxTextCtrl { 17 21 Process proc; 18 LineIterator!(char) li;19 22 bool fin = false; 20 23 … … 24 27 proc = new Process(cmd, Environment.get()); 25 28 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 } 27 37 28 38 // set up the text area … … 38 48 39 49 // 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]); 45 57 } 58 } catch (Exception e) {} // ignore errors 59 (cast(wxIdleEvent) e).RequestMore(); 46 60 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 } 50 65 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]); 53 74 } 54 } 75 } catch (Exception e) {} // ignore errors 55 76 } 56 77 }
