Fix flushing mechanics for input writer in native pipe

This commit is contained in:
Sergei Vorobev
2016-11-15 14:49:39 -08:00
parent 584aec7c92
commit df6662aa2e
@@ -1631,15 +1631,19 @@ namespace System.Management.Automation
/// <param name="input"></param>
internal void Add(object input)
{
if (_stopping || _streamWriter == null)
{
// if _streamWriter is already null, then we already called Done()
// so we should just discard the input.
return;
}
Array formattedObjects = _pipeline.Process(input);
if (_stopping) return;
foreach (var item in formattedObjects)
{
string line = PSObject.ToStringParser(_command.Context, item);
_streamWriter.WriteLine(line);
}
_streamWriter.Flush();
}
/// <summary>
@@ -1670,8 +1674,9 @@ namespace System.Management.Automation
Encoding pipeEncoding = _command.Context.GetVariableValue(SpecialVariables.OutputEncodingVarPath) as System.Text.Encoding ??
Encoding.ASCII;
_streamWriter = new StreamWriter(process.StandardInput.BaseStream,
pipeEncoding);
_streamWriter = new StreamWriter(process.StandardInput.BaseStream, pipeEncoding);
_streamWriter.AutoFlush = true;
_inputFormat = inputFormat;
}
@@ -1696,7 +1701,8 @@ namespace System.Management.Automation
// streamWriter is present, only if we call Start method
if (_streamWriter != null)
{
_streamWriter.Dispose();
_streamWriter.Close();
_streamWriter = null;
}
}
}