我要做的是从我的C应用程序运行Python脚本。你知道吗
我在这里阅读了许多线程,并将以下代码放在一起:
private void RunPythonScript(string py1, string py2)
{
try
{
ProcessStartInfo start = new ProcessStartInfo
{
FileName = py1,
Arguments = py2,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
string stderr = process.StandardError.ReadToEnd();
Console.Write(stderr);
Console.Write(result);
}
}
}
catch (Exception ex)
{
Helpers.ReturnMessage(ex.ToString());
}
}
private void RunPythonScriptToolStripMenuItem_Click(object sender, EventArgs e)
{
string py1 = @"C:\Users\Graham\AppData\Local\Programs\Python\Python37-32\python.exe";
string py2 = @"C:\Users\Graham\Desktop\Files\programming\PaydayDreamsProgramming\Python\scripts\domain-seo-analyzer\domain_seo_analyzer.py";
RunPythonScript(py1, py2);
}
这似乎相当直截了当。你知道吗
问题是:python.exe
命令控制台弹出空白,因此我假设脚本没有运行。没有错误,我可以去,只是一个空白的控制台框。你知道吗
我的代码中有什么遗漏了吗?(我假设这是一个C#错误)指向.exe和.py的路径都是完全正确的。你知道吗
我不知道还有什么要查的,如有任何帮助,将不胜感激。你知道吗
CommandLineProcess类-启动命令行进程并等待它完成。将捕获所有标准输出/错误,并且不会为流程启动单独的窗口:
然后像这样使用:
如果你仍然有错误,请随时通知我。你知道吗
相关问题 更多 >
编程相关推荐