mirror of https://github.com/winsw/winsw
[Issue #218] StdOut was not being redirected properly and was causing the child process to hang.
parent
33dcc39539
commit
5fb03bb094
|
@ -138,9 +138,9 @@ namespace winsw.Util
|
||||||
ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory;
|
ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory;
|
||||||
ps.CreateNoWindow = false;
|
ps.CreateNoWindow = false;
|
||||||
ps.UseShellExecute = false;
|
ps.UseShellExecute = false;
|
||||||
ps.RedirectStandardInput = true; // this creates a pipe for stdin to the new process, instead of having it inherit our stdin.
|
ps.RedirectStandardInput = false;
|
||||||
ps.RedirectStandardOutput = true;
|
ps.RedirectStandardOutput = false;
|
||||||
ps.RedirectStandardError = true;
|
ps.RedirectStandardError = false;
|
||||||
|
|
||||||
if (envVars != null)
|
if (envVars != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,9 +4,10 @@ using NUnit.Framework;
|
||||||
using winsw;
|
using winsw;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using winsw.Util;
|
using winsw.Util;
|
||||||
|
using System.Collections.Generic;
|
||||||
namespace winswTests.Util
|
|
||||||
{
|
namespace winswTests.Util
|
||||||
|
{
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
class ProcessHelperTest
|
class ProcessHelperTest
|
||||||
|
@ -47,5 +48,35 @@ namespace winswTests.Util
|
||||||
Assert.That(!envVars.ContainsKey("computername"), "Test error: the environment parsing logic is case-insensitive");
|
Assert.That(!envVars.ContainsKey("computername"), "Test error: the environment parsing logic is case-insensitive");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
[Test]
|
||||||
|
public void ShouldNotHangWhenWritingLargeStringToStdOut()
|
||||||
|
{
|
||||||
|
var tmpDir = FilesystemTestHelper.CreateTmpDirectory();
|
||||||
|
String scriptFile = Path.Combine(tmpDir, "print_lots_to_stdout.bat");
|
||||||
|
var lotsOfStdOut = string.Join("", _Range(1,1000));
|
||||||
|
File.WriteAllText(scriptFile, string.Format("echo \"{0}\"", lotsOfStdOut));
|
||||||
|
|
||||||
|
Process proc = new Process();
|
||||||
|
var ps = proc.StartInfo;
|
||||||
|
ps.FileName = scriptFile;
|
||||||
|
|
||||||
|
ProcessHelper.StartProcessAndCallbackForExit(proc);
|
||||||
|
var exited = proc.WaitForExit(5000);
|
||||||
|
if (!exited)
|
||||||
|
{
|
||||||
|
Assert.Fail("Process " + proc + " didn't exit after 5 seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] _Range(int start, int limit)
|
||||||
|
{
|
||||||
|
var range = new List<string>();
|
||||||
|
for(var i = start; i<limit; i++)
|
||||||
|
{
|
||||||
|
range.Add(i.ToString());
|
||||||
|
}
|
||||||
|
return range.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue