ProcessStartInfo,python.exe:无法打开文件 [Errno 22] 参数无效
ProcessStartInfo, python.exe: can't open file [Errno 22] Invalid argument
我有一个 python 脚本 'saudilp.py'(它分析车牌号),我尝试 运行 这个脚本在 c#
中
此 C# 代码:
// 1) create process info
ProcessStartInfo start = new ProcessStartInfo();
//cmd is full path to python.exe
start.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe";
// 2) Provide script and arguments
string arg = "s10.jpeg";
string pathScript = "D:/graduation project/pythonOCRtest/pythonOCRtest/OCR/saudilp.py";
start.Arguments = $"\"{pathScript}\"\"{arg}\""; //args is path to .py file and any cmd line args
// 3) process configuration
start.UseShellExecute = false;
start.CreateNoWindow = true; //do not create window
start.RedirectStandardOutput = true; //recive print lines from the script
start.RedirectStandardError = true;
// 4) Execute process and get output
string result = "";
string errors = "";
using (Process process = Process.Start(start))
{
errors = process.StandardError.ReadToEnd();
result = process.StandardOutput.ReadToEnd();
}
// 5) display output
Console.WriteLine("ERRORS:");
Console.WriteLine(errors);
Console.WriteLine();
Console.WriteLine("RESULTS:");
Console.WriteLine(result);
控制台打印此错误:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe: 无法打开文件 'D:\graduation project\pythonOCRtest\pythonOCRtest\OCR\saudilp.py"s10.jpeg': [Errno 22] 参数无效
你的论点似乎有一个额外的 \,试试
start.Arguments = $"\"{pathScript}\" {arg}\"";
您可能还需要 set-up 工作目录
start.WorkingDirectory = 路径
我有一个 python 脚本 'saudilp.py'(它分析车牌号),我尝试 运行 这个脚本在 c#
中此 C# 代码:
// 1) create process info
ProcessStartInfo start = new ProcessStartInfo();
//cmd is full path to python.exe
start.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe";
// 2) Provide script and arguments
string arg = "s10.jpeg";
string pathScript = "D:/graduation project/pythonOCRtest/pythonOCRtest/OCR/saudilp.py";
start.Arguments = $"\"{pathScript}\"\"{arg}\""; //args is path to .py file and any cmd line args
// 3) process configuration
start.UseShellExecute = false;
start.CreateNoWindow = true; //do not create window
start.RedirectStandardOutput = true; //recive print lines from the script
start.RedirectStandardError = true;
// 4) Execute process and get output
string result = "";
string errors = "";
using (Process process = Process.Start(start))
{
errors = process.StandardError.ReadToEnd();
result = process.StandardOutput.ReadToEnd();
}
// 5) display output
Console.WriteLine("ERRORS:");
Console.WriteLine(errors);
Console.WriteLine();
Console.WriteLine("RESULTS:");
Console.WriteLine(result);
控制台打印此错误:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe: 无法打开文件 'D:\graduation project\pythonOCRtest\pythonOCRtest\OCR\saudilp.py"s10.jpeg': [Errno 22] 参数无效
你的论点似乎有一个额外的 \,试试
start.Arguments = $"\"{pathScript}\" {arg}\"";
您可能还需要 set-up 工作目录
start.WorkingDirectory = 路径