public GetStandardOutputAsString ( ) : string | ||
Результат | string |
internal static string ExecuteSystemProcess(string command, string args, string workingdir) { ProcessStartInfo si = new ProcessStartInfo { FileName = command, Arguments = args, WorkingDirectory = workingdir, CreateNoWindow = true }; Program program = new Program(si); program.Start(); while (!program.WaitForExit(100)) { } string standardOutputAsString = program.GetStandardOutputAsString(); program.Dispose(); return standardOutputAsString; }
public static int RunAndWait(string fileName, string arguments, out string result, [Optional, DefaultParameterValue(null)] IDictionary<string, string> environmentVariables) { ProcessStartInfo si = new ProcessStartInfo(fileName, arguments) { CreateNoWindow = true, RedirectStandardOutput = true, UseShellExecute = false }; if (environmentVariables != null) { foreach (KeyValuePair<string, string> pair in environmentVariables) { si.EnvironmentVariables.Add(pair.Key, pair.Value); } } using (Program program = new Program(si)) { program.Start(); program.WaitForExit(); result = program.GetStandardOutputAsString(); return program.ExitCode; } }