private void buttonTest_Click(object sender, EventArgs e) { try { string[] launchCommand = new string[] { Filename, StartupFolder, Parameters, Enum.GetName(typeof(ProcessWindowStyle), StartState), false.ToString(), UseShellExecute.ToString(), false.ToString(), ForceWindowFocus.ToString() }; Common.ProcessRunCommand(launchCommand); } catch (Exception ex) { IrssLog.Error("Test Application: {0}", ex.ToString()); } }
protected sealed override object getValue() { var processStartInfo = new ProcessStartInfo(); if (FileName != null) { processStartInfo.FileName = FileName.GetValue(); } if (Arguments != null) { processStartInfo.Arguments = Arguments.GetValue(); } if (CreateNoWindow != null) { processStartInfo.CreateNoWindow = CreateNoWindow.GetValue(); } if (UseShellExecute != null) { processStartInfo.UseShellExecute = UseShellExecute.GetValue(); } if (RedirectStandardInput != null) { processStartInfo.RedirectStandardInput = RedirectStandardInput.GetValue(); } if (RedirectStandardOutput != null) { processStartInfo.RedirectStandardOutput = RedirectStandardOutput.GetValue(); } if (RedirectStandardError != null) { processStartInfo.RedirectStandardError = RedirectStandardError.GetValue(); } if (Domain != null) { processStartInfo.Domain = Domain.GetValue(); } if (UserName != null) { processStartInfo.UserName = UserName.GetValue(); } if (Password != null) { processStartInfo.Password = Password.GetValue(); } if (ErrorDialog != null) { processStartInfo.ErrorDialog = ErrorDialog.GetValue(); } if (ErrorDialogParentHandle != null) { processStartInfo.ErrorDialogParentHandle = ErrorDialogParentHandle.GetValue(); } if (LoadUserProfile != null) { processStartInfo.LoadUserProfile = LoadUserProfile.GetValue(); } if (PasswordInClearText != null) { processStartInfo.PasswordInClearText = PasswordInClearText.GetValue(); } if (StandardOutputEncoding != null) { processStartInfo.StandardOutputEncoding = StandardOutputEncoding.GetValue(); } if (StandardErrorEncoding != null) { processStartInfo.StandardErrorEncoding = StandardErrorEncoding.GetValue(); } if (Verb != null) { processStartInfo.Verb = Verb.GetValue(); } if (WindowStyle != null) { processStartInfo.WindowStyle = WindowStyle.GetValue(); } if (WorkingDirectory != null) { processStartInfo.WorkingDirectory = WorkingDirectory.GetValue(); } return(processStartInfo); }
private void ExecuteInvoke(object contextObject) { CodeActivityContext context = contextObject as CodeActivityContext; string commandLine = FileName.Get(context) + " " + Arguments.Get(context); bool useShellExecute = UseShellExecute.Get <bool>(context); bool showWindow = ShowWindow.Get <bool>(context); string stdOut = string.Empty; string errOut = string.Empty; bool isNative = IsNative.Get(context); WriteLineConsole((useShellExecute ? "Open : " : "") + commandLine); Process processRunner = new Process(); if (isNative) { processRunner.StartInfo.FileName = Environment.GetEnvironmentVariable("COMSPEC"); } else { processRunner.StartInfo.FileName = FileName.Get(context); processRunner.StartInfo.Arguments = Arguments.Get(context); } processRunner.StartInfo.WorkingDirectory = WorkingDirectory.Get <string>(context); processRunner.StartInfo.UseShellExecute = useShellExecute; processRunner.StartInfo.CreateNoWindow = showWindow; processRunner.StartInfo.Verb = Verb.Get <string>(context); if (!useShellExecute && !showWindow) { processRunner.StartInfo.RedirectStandardOutput = true; processRunner.StartInfo.RedirectStandardError = true; processRunner.StartInfo.RedirectStandardInput = true; } try { processRunner.Start(); } catch (Exception ex) { ExitCode.Set(context, 1); if (ThrowOnExitCode.Get <bool>(context)) { throw new InvalidOperationException(ex.Message); } else { WriteLineConsole(ex.Message); Output.Set(context, ex.Message); } return; } if (!useShellExecute && !showWindow) { if (IsNative.Get(context)) { processRunner.StandardInput.WriteLine("echo off"); processRunner.StandardInput.WriteLine(commandLine); processRunner.StandardInput.WriteLine("exit"); } string outPutLine; string outPut = string.Empty; bool blockedOutput = IsNative.Get(context); while ((outPutLine = processRunner.StandardOutput.ReadLine()) != null) { if ((blockedOutput) || (outPutLine == "exit")) { if (outPutLine == commandLine) { blockedOutput = false; } continue; } stdOut += outPutLine + "\n"; WriteLineConsole(outPutLine); } while ((outPutLine = processRunner.StandardError.ReadLine()) != null) { if ((blockedOutput) || (outPutLine == "exit")) { if (outPutLine == commandLine) { blockedOutput = false; } continue; } errOut += outPutLine + "\n"; WriteLineConsole(outPutLine); } processRunner.WaitForExit(); ExitCode.Set(context, processRunner.ExitCode); bool success = (processRunner.ExitCode == 0); if (success) { Output.Set(context, stdOut); } else { if (!ThrowOnExitCode.Get <bool>(context)) { Output.Set(context, errOut); } } if (processRunner != null && !processRunner.HasExited) { processRunner.Kill(); processRunner = null; } if (!success && ThrowOnExitCode.Get <bool>(context)) { throw new InvalidOperationException(errOut); } } }