mirror of https://github.com/winsw/winsw
Merge pull request #220 from greenhouse-org/fix_218
[Issue #218] StdOut was not being redirected properly and was causing…pull/224/head
commit
10c1ec3e77
|
@ -138,9 +138,9 @@ namespace winsw.Util
|
|||
ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory;
|
||||
ps.CreateNoWindow = 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.RedirectStandardOutput = true;
|
||||
ps.RedirectStandardError = true;
|
||||
ps.RedirectStandardInput = false;
|
||||
ps.RedirectStandardOutput = false;
|
||||
ps.RedirectStandardError = false;
|
||||
|
||||
if (envVars != null)
|
||||
{
|
||||
|
|
|
@ -4,9 +4,10 @@ using NUnit.Framework;
|
|||
using winsw;
|
||||
using System.IO;
|
||||
using winsw.Util;
|
||||
|
||||
namespace winswTests.Util
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace winswTests.Util
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
class ProcessHelperTest
|
||||
|
@ -47,5 +48,35 @@ namespace winswTests.Util
|
|||
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