运行 python 来自 C# 的脚本
Running python script from C#
我正在尝试使用 C#运行python 脚本
并且从 shell 正在打开,但是脚本没有 运行
我知道它应该创建一个文件
如何运行流程?
Process p = new Process(); // create process (i.e., the python program
p.StartInfo.FileName = @"C:\Python27\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the output from stdout
p.StartInfo.Arguments = @"T:\barakr0_3G_daily_report16.03.1515319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
p.Start();
也许你需要在这行的每个'\'中加上两个'\':
p.StartInfo.Arguments = @"T:\barakr0_3G_daily_report16.03.1515319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
查看此网页:https://bytes.com/topic/python/insights/950783-two-ways-run-python-programs-c
编辑:
这样试试:
p.StartInfo.Arguments = @"T:\barakr\360_3G_daily_report\2016.03.15\0615319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
希望对您有所帮助:)
我认为你有一个双反斜杠,在这一行的末尾应该是一个反斜杠:
p.StartInfo.Arguments = @"T:\barakr0_3G_daily_report16.03.1515319253\powerlink_logs_mrg.py";
我觉得你的代码很合适。双斜线应该不是必需的,因为字符串常量前面有@。我建议您尝试将 exe 路径和参数路径复制并粘贴到 shell window,然后 运行 将 shell window 中的 exe 复制到确保您在这些路径中没有错字。
要在字符串中添加反斜杠,您需要像这样对其进行转义:"\"
因此您的代码将是:
Process p = new Process(); // create process (i.e., the python program
p.StartInfo.FileName = @"C:\Python27\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the output from stdout
p.StartInfo.Arguments = @"T:\barakr\360_3G_daily_report\2016.03.15\0615319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
p.Start();
祝你有愉快的一天,希望我能帮到你 ;)
编辑:显然,当字符串前有 @ 时,不需要双反斜杠。尝试直接使用您的操作系统测试您的位置。
我正在尝试使用 C#运行python 脚本
并且从 shell 正在打开,但是脚本没有 运行
我知道它应该创建一个文件
如何运行流程?
Process p = new Process(); // create process (i.e., the python program
p.StartInfo.FileName = @"C:\Python27\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the output from stdout
p.StartInfo.Arguments = @"T:\barakr0_3G_daily_report16.03.1515319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
p.Start();
也许你需要在这行的每个'\'中加上两个'\':
p.StartInfo.Arguments = @"T:\barakr0_3G_daily_report16.03.1515319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
查看此网页:https://bytes.com/topic/python/insights/950783-two-ways-run-python-programs-c
编辑:
这样试试:
p.StartInfo.Arguments = @"T:\barakr\360_3G_daily_report\2016.03.15\0615319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
希望对您有所帮助:)
我认为你有一个双反斜杠,在这一行的末尾应该是一个反斜杠:
p.StartInfo.Arguments = @"T:\barakr0_3G_daily_report16.03.1515319253\powerlink_logs_mrg.py";
我觉得你的代码很合适。双斜线应该不是必需的,因为字符串常量前面有@。我建议您尝试将 exe 路径和参数路径复制并粘贴到 shell window,然后 运行 将 shell window 中的 exe 复制到确保您在这些路径中没有错字。
要在字符串中添加反斜杠,您需要像这样对其进行转义:"\"
因此您的代码将是:
Process p = new Process(); // create process (i.e., the python program
p.StartInfo.FileName = @"C:\Python27\python.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false; // make sure we can read the output from stdout
p.StartInfo.Arguments = @"T:\barakr\360_3G_daily_report\2016.03.15\0615319253\powerlink_logs_mrg.py"; //PanelsDirectory[j] + "\powerlink_logs_mrg.py"; // start the python program with two parameters
p.Start();
祝你有愉快的一天,希望我能帮到你 ;)
编辑:显然,当字符串前有 @ 时,不需要双反斜杠。尝试直接使用您的操作系统测试您的位置。