【发布时间】:2023-03-14 15:05:01
【问题描述】:
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = ;
start.Arguments = ;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
我有这个 python 代码可以从 c# 执行 python。但我不知道在这两个变量中放入什么。
编辑
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"U:\Documents\entsoe-py-master\tests\test_data\python.exe";
start.Arguments = @"U:\Documents\entsoe-py-master\tests\test_data\request.py 31.12.2016 01.01.2017 datatype"; // give filename, dates from the UI to python and query datatype
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
我收到此错误:
System.ComponentModel.Win32Exception: 'The system cannot find the file specified'
在这条线上using (Process process = Process.Start(start))
【问题讨论】:
-
是否有可能因为管理员权限而找不到文件?我的意思是,路径很好,这不应该是问题
-
好的,如果我将文件放在我的 C: 目录中,我会找到该文件。我不知道为什么它在我的 U: 中找不到文件。
-
我不知道你的U盘在哪里,但是我们在C盘安装python并且进程从C:驱动它自己运行。如果我的回答有帮助,那就采纳吧
-
这个错误与你在这里问的无关,这个错误与python有关,请再发一个问题;我会要求您在发布问题之前进行研究。 我希望与 Process.Start 或在 C# 中运行 python 文件相关的问题得到解决