Created
July 21, 2014 13:36
-
-
Save gokulraja/a216e7e50176a91dbc6a to your computer and use it in GitHub Desktop.
Process Start Helper C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ProcessHelper(string fileName, string arguments, bool showResultsinConsole) | |
{ | |
// Start the child process. | |
using (var p = new Process{ | |
StartInfo = | |
{ | |
UseShellExecute = false, | |
CreateNoWindow = true, | |
RedirectStandardOutput = true, | |
FileName = fileName | |
} | |
}) | |
{ | |
// Redirect the output stream of the child process. | |
if (!string.IsNullOrEmpty(arguments)) | |
p.StartInfo.Arguments = arguments; | |
if(!string.IsNullOrEmpty(Path.GetDirectoryName(fileName))) | |
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileName); | |
p.Start(); | |
// Do not wait for the child process to exit before | |
// reading to the end of its redirected stream. | |
// p.WaitForExit(); | |
// Read the output stream first and then wait. | |
string output = p.StandardOutput.ReadToEnd(); | |
if (showResultsinConsole) | |
Console.WriteLine(output); | |
p.WaitForExit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup basic authentication in C#
const bool showResultsinConsole = true;
Console.WriteLine("Setting up IIS Basic authentication");
//@"%windir%\system32\inetsrv\appcmd.exe set config /section:anonymousAuthentication /enabled:false",