www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - pipeProcess: read stdout and stderror simultaneously

reply unDEFER <undefer gmail.com> writes:
Hello!
I'm trying to run rsync and handle errors and operation progress 
at the same time:

================
auto rsync_pipes = pipeProcess(["rsync", "-avu", "--delete", 
path, copy_to], Redirect.stdout | Redirect.stderr);
     scope(exit) wait(df_pipes.pid);

foreach (df_line; df_pipes.stdout.byLine)
{
     //This will read stdout till finishing the process
}

foreach (df_line; df_pipes.stderr.byLine)
{
     //Handle errors when it is already not actual???
}
================

So, I need one of 2 option:
1) Not blocking byLine() to read df_pipes.stdout and 
df_pipes.stderr in the loop like:
while (!ProcessFinished)
{
foreach (df_line; df_pipes.stdout.notBlockingByLine)
{
     //Handle progress
}
foreach (df_line; df_pipes.stderr.notBlockingByLine)
{
     //Handle errors
}
}
Nov 13 2016
parent reply unDEFER <undefer gmail.com> writes:
2) Some magic function which join stderr with stdout together:
foreach (df_line; 
df_pipes.stdout_joined_with_stderr.notBlockingByLine)
{
     //Handle progress
}

Thank you in advance.
Nov 13 2016
parent unDEFER <undefer gmail.com> writes:
I have found! The magic word is Redirect.stderrToStdout. So the 
right code:

==========
auto rsync_pipes = pipeProcess(["rsync", archieve_option, "-vu", 
"--delete", path, copy_to], Redirect.stdout | 
Redirect.stderrToStdout);
scope(exit) wait(df_pipes.pid);

foreach (df_line; df_pipes.stdout.byLine)
{
// Handle errors and progress simultaneously
}
==========

Thank you.
Nov 13 2016