Skip to content

Instantly share code, notes, and snippets.

@tdmitch
Created December 15, 2016 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdmitch/8e9444676dcfa79e5ba79f4bb8f60218 to your computer and use it in GitHub Desktop.
Save tdmitch/8e9444676dcfa79e5ba79f4bb8f60218 to your computer and use it in GitHub Desktop.
try
{
// Create new ProcessStartInfo with vars from above
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = exeName;
ps.Arguments = args;
ps.UseShellExecute = false;
ps.RedirectStandardError = true;
ps.RedirectStandardOutput = true;
ps.CreateNoWindow = true;
Process p = Process.Start(ps);
// Capture StdOut and StdErr into variables
Dts.Variables["vStdOutput"].Value = p.StandardOutput.ReadToEnd();
Dts.Variables["vStdError"].Value = p.StandardError.ReadToEnd();
// Wait for exit
p.WaitForExit();
// Capture the exit code (0 = success)
Dts.Variables["vExitCode"].Value = p.ExitCode;
// Write standard output to log
bool fireAgain = true;
Dts.Events.FireInformation(0, "7Zip completion", Dts.Variables["vStdOutput"].Value.ToString(), string.Empty, 0, ref fireAgain);
}
catch (Exception ex)
{
exceptionTxt = ex.Message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment