-
Notifications
You must be signed in to change notification settings - Fork 651
Added /exec and /proj arguments #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
namespace GitVersion | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
static class ProcessHelper | ||
{ | ||
private static volatile object _lockObject = new object(); | ||
|
||
// http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/f6069441-4ab1-4299-ad6a-b8bb9ed36be3 | ||
public static Process Start(ProcessStartInfo startInfo) | ||
{ | ||
Process process; | ||
|
||
lock (_lockObject) | ||
{ | ||
using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox)) | ||
{ | ||
process = Process.Start(startInfo); | ||
process.PriorityClass = ProcessPriorityClass.Idle; | ||
} | ||
} | ||
|
||
return process; | ||
} | ||
|
||
// http://csharptest.net/532/using-processstart-to-capture-console-output/ | ||
public static int Run(Action<string> output, Action<string> errorOutput, TextReader input, string exe, string args, string workingDirectory) | ||
{ | ||
if (String.IsNullOrEmpty(exe)) | ||
throw new FileNotFoundException(); | ||
if (output == null) | ||
throw new ArgumentNullException("output"); | ||
|
||
var psi = new ProcessStartInfo | ||
{ | ||
UseShellExecute = false, | ||
RedirectStandardError = true, | ||
RedirectStandardOutput = true, | ||
RedirectStandardInput = true, | ||
WindowStyle = ProcessWindowStyle.Hidden, | ||
CreateNoWindow = true, | ||
ErrorDialog = false, | ||
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory, | ||
FileName = exe, | ||
Arguments = args | ||
}; | ||
|
||
using (var process = Process.Start(psi)) | ||
using (var mreOut = new ManualResetEvent(false)) | ||
using (var mreErr = new ManualResetEvent(false)) | ||
{ | ||
process.EnableRaisingEvents = true; | ||
process.OutputDataReceived += (o, e) => | ||
{ | ||
// ReSharper disable once AccessToDisposedClosure | ||
if (e.Data == null) | ||
mreOut.Set(); | ||
else | ||
output(e.Data); | ||
}; | ||
process.BeginOutputReadLine(); | ||
process.ErrorDataReceived += (o, e) => | ||
{ | ||
// ReSharper disable once AccessToDisposedClosure | ||
if (e.Data == null) | ||
mreErr.Set(); | ||
else | ||
errorOutput(e.Data); | ||
}; | ||
process.BeginErrorReadLine(); | ||
|
||
string line; | ||
while (input != null && null != (line = input.ReadLine())) | ||
process.StandardInput.WriteLine(line); | ||
|
||
process.StandardInput.Close(); | ||
process.WaitForExit(); | ||
|
||
mreOut.WaitOne(); | ||
mreErr.WaitOne(); | ||
|
||
return process.ExitCode; | ||
} | ||
} | ||
|
||
[Flags] | ||
enum ErrorModes | ||
{ | ||
FailCriticalErrors = 0x1, | ||
NoGpFaultErrorBox = 0x2 | ||
} | ||
|
||
struct ChangeErrorMode : IDisposable | ||
{ | ||
private readonly int _oldMode; | ||
|
||
public ChangeErrorMode(ErrorModes mode) | ||
{ | ||
_oldMode = SetErrorMode((int)mode); | ||
} | ||
|
||
void IDisposable.Dispose() { SetErrorMode(_oldMode); } | ||
|
||
[DllImport("kernel32.dll")] | ||
private static extern int SetErrorMode(int newMode); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need these as solution items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly so readme is easily accessed so it gets updated when things are changed. Happy to revert though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah that is fine. was just curious