我有一个简单的Python脚本,试图在Visual Studio C#中运行。 该脚本可以从cmd窗口正常运行,但是无法在Visual Studio中执行。
test.py Python脚本 打印(“ Hello World”)
try
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\....\....\Python\Python37-32\python.exe";
String pathToFile = @"C:\.....\.....\test.py";
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (System.Diagnostics.Process process = System.Diagnostics.Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
String result = JsonConvert.SerializeObject(reader.ReadToEnd());
Response.Write(result);
}
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}