Вы можете запустить новый Process
в коде C # для запуска python и запустить ваш скрипт.
Вы можете запустить новый процесс, вызывающий python.Смотрите образец с комментариями:
ProcessStartInfo start = new ProcessStartInfo();
// full path of python exe
start.FileName = "c:\\Python\\Python.exe";
string cmd = "C:\\scripts\\test.py";
string args = "";
// define the script with arguments (if you need them).
start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args);
// Do not use OS shell
start.UseShellExecute = false;
// You do not need new window
start.CreateNoWindow = true;
// Any output, generated by application will be redirected back
start.RedirectStandardOutput = true;
// Any error in standard output will be redirected back (for example exceptions)
start.RedirectStandardError = true;
// start the process
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
// Here are the exceptions from our Python script
string stderr = process.StandardError.ReadToEnd();
// Here is the result of StdOut(for example: print "test")
string result = reader.ReadToEnd();
return result;
}
}