将参数从C#传递到Python

将参数从C#传递到Python,c#,python,ironpython,C#,Python,Ironpython,我想使用ProcessStartInfo将参数从C#代码传递给Python。我不得不避免使用IronPython(通过创建范围),因为它与numpy不兼容。我找到了一些不成功的答案。 以下是我写的: var x = 8; string arg = string.Format(@"C:\Users\ayed\Desktop\IronPythonExamples\RunExternalScript\plot.py", x); try {

我想使用ProcessStartInfo将参数从C#代码传递给Python。我不得不避免使用IronPython(通过创建范围),因为它与numpy不兼容。我找到了一些不成功的答案。 以下是我写的:

var x = 8;
        string arg = string.Format(@"C:\Users\ayed\Desktop\IronPythonExamples\RunExternalScript\plot.py", x);
        try
        {
            Process p = new Process();
            p.StartInfo = new ProcessStartInfo(@"D:\WinPython\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\python.exe", arg);
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();
            p.WaitForExit();
        }
        catch (Exception ex)
         {
             Console.WriteLine("There is a problem in your Python code: " + ex.Message);
         }

         Console.WriteLine("Press enter to exit...");
         Console.ReadLine();
测试python代码允许绘制曲线并打印x的值。对于曲线,可以,但我得到了一个例外:没有定义名称“x”


如何正确地将变量传递给此python代码?

看起来
x
应该是
plot.py
的参数,但您忘记了将
x
添加到
arg

string.Format(@"C:\Users\ayed\Desktop\IronPythonExamples\RunExternalScript\plot.py {0}", x);

谢谢Gabriel,我刚刚尝试过这个,我一直都有同样的问题。不,我只是希望它能从C#那里传递过来。从命令行读取x的值是什么意思?您希望将
x
传递到
plot.py
“照原样”,这到底是什么意思?我认为x的值可以以类似于IronPython的方式传递,而无需从命令行读取。我怎样才能从命令行读取它呢?您必须修改Python代码,以将该值作为命令行参数或通过其标准输入接受。如果没有看到调用的python代码,我们无法告诉您要更改什么。