Changeset 149
- Timestamp:
- 05/14/06 11:43:30 (3 years ago)
- Files:
-
- trunk/Makefile.Duit (added)
- trunk/demos/gtk/SpawnTests.d (modified) (1 diff)
- trunk/src/glib/Spawn.d (modified) (5 diffs)
- trunk/src/glib/Str.d (modified) (2 diffs)
- trunk/wrap/APILookupGLib.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demos/gtk/SpawnTests.d
r148 r149 83 83 } 84 84 Spawn spawn = new Spawn(args[0]); 85 spawn.addChildWatch(&childEnded); 85 86 if (args.length > 1 ) 86 87 { 87 88 for( int i=1 ; i<args.length ; i++ ) 88 89 { 90 writefln("SpawnTests.exec adding parameter [%s] %s",i,args[i]); 89 91 spawn.addParm(args[i]); 90 92 } 91 93 } 92 spawn.addParm(null);94 //spawn.addParm(null); 93 95 return exec(spawn); 96 } 97 98 void childEnded(int process, int status) 99 { 100 writefln("process %s ended with status %s", process, status); 94 101 } 95 102 trunk/src/glib/Spawn.d
r148 r149 63 63 private import std.c.string;; 64 64 65 private import std.thread; 66 65 67 /** 66 68 * Description … … 110 112 } 111 113 114 /** 115 * Adds a delegate to be notified on the end of the child process. 116 * Params: 117 * delegate(int = 118 * dlg = 119 */ 112 120 public void addChildWatch(void delegate(int,int) dlg) 113 121 { … … 166 174 * Executes the prepared process 167 175 */ 168 public int execAsyncWithPipes() 169 { 176 public int execAsyncWithPipes( 177 void delegate(int, int, char[], char[])endChild=null, 178 bool delegate(char[])outReader=null, 179 bool delegate(char[])errReader=null, 180 ) 181 { 182 writefln("Spawn.execAsyncWithPipes 1"); 183 writefln("Spawn.execAsyncWithPipes argv.length = %s",argv.length); 170 184 char** command = Str.toStringzArray(argv); 171 185 char* parm = *command; … … 198 212 standardOutput = fdopen(stdOut, "r"); 199 213 standardError = fdopen(stdErr, "r"); 214 215 if ( outReader !is null ) 216 { 217 //(new SpawnOutRead(outReader)).start(); 218 readLoop(outReader); 219 } 200 220 } 201 221 202 222 return result; 203 223 } 224 225 int readLoop(bool delegate(char[])outReader) 226 { 227 writefln("SpawnOutRead.run 1"); 228 while ( !endOfOutput() ) 229 { 230 writefln("SpawnOutRead.run 2"); 231 char[] line = readLine(); 232 writefln("\t%s", line); 233 outReader(line); 234 writefln("SpawnOutRead.run 3"); 235 } 236 writefln("SpawnOutRead.readLoop 4"); 237 if ( externalWatch !is null ) 238 { 239 writefln("Spawn.readLoop 2"); 240 externalWatch(childPid, 0); 241 } 242 return 0; 243 } 244 245 // class SpawnOutRead : Thread 246 // { 247 // bool delegate(char[])outReader; 248 // this(bool delegate(char[])outReader) 249 // { 250 // this.outReader = outReader; 251 // } 252 // 253 // int run() 254 // { 255 // return readLoop(outReader); 256 // } 257 // } 258 259 260 204 261 205 262 public char[] readLine(int max=4096) … … 231 288 extern(C) static void childWatchCallback(int pid, int status, Spawn spawn) 232 289 { 290 writefln("Spawn.childWatchCallback 1"); 233 291 if ( spawn.externalWatch !is null ) 234 292 { 293 writefln("Spawn.childWatchCallback 2"); 235 294 spawn.externalWatch(pid, status); 236 295 } 296 writefln("Spawn.childWatchCallback 3"); 237 297 spawn.close(); 238 298 } trunk/src/glib/Str.d
r148 r149 140 140 foreach ( int i, char[] arg ; args) 141 141 { 142 writefln("Str o.toStringArray [%s] >%s<", i, arg);142 writefln("Str.toStringArray [%s] >%s<", i, arg); 143 143 } 144 144 … … 149 149 foreach (char[] p; args) 150 150 { 151 writefln("Str.toStringzArray put .%s.", p);151 writefln("Str.toStringzArray put \"%s\"", p); 152 152 argv[argc++] = toStringz(p); 153 153 } trunk/wrap/APILookupGLib.txt
r147 r149 675 675 } 676 676 677 /** 678 * Adds a delegate to be notified on the end of the child process. 679 * Params: 680 * delegate(int = 681 * dlg = 682 */ 677 683 public void addChildWatch(void delegate(int,int) dlg) 678 684 {
