Skip to content

Instantly share code, notes, and snippets.

@r3ne-pew
Created November 4, 2016 07:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save r3ne-pew/4d31036c8ba508ef936ac940f50cc685 to your computer and use it in GitHub Desktop.
Save r3ne-pew/4d31036c8ba508ef936ac940f50cc685 to your computer and use it in GitHub Desktop.
Run Python Script in c#
private void run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = cmd;//cmd is full path to python.exe
start.Arguments = args;//args is path to .py file and any cmd line args
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using(Process process = Process.Start(start))
{
using(StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment