digitalmars.D.learn - Faster ways to redirect stdout of child process to file
- Thomas Mader (13/13) Aug 11 2014 I use
- Thomas Mader (10/10) Aug 15 2014 I found out that the redirect was not responsible for the CPU
I use auto pipes = pipeProcess( cmd, Redirect.stdout | Redirect.stderr ); to redirect stdout of the newly created subprocess via pipes to a file. The redirect itself happens in a newly created thread (because I need to wait for the subprocess to finish to take the exact elapsed time) doing basically: pipes.stdout.byChunk( 1024 * 1024 ).copy( cof.lockingTextWriter() ); This happens to use much of my CPU time (~25%). I wonder if there is no faster way to do this. I use this method because I want to be platform independent. Thomas
Aug 11 2014
I found out that the redirect was not responsible for the CPU time, it was some other code part which was responsible for it and totally unrelated to the redirect. I also saw that a redirect in my case is much simpler by using spawnProcess: auto logFile = File("errors.log", "w"); auto pid = spawnProcess(["dmd", "myprog.d"], std.stdio.stdin, std.stdio.stdout, logFile);
Aug 15 2014