从C#应用程序向IronPython传递命令行参数?
如何将命令行参数从C#应用程序传递到IronPython 2.x?谷歌只返回了关于如何使用IronPython1.x的结果从C#应用程序向IronPython传递命令行参数?,c#,ironpython,C#,Ironpython,如何将命令行参数从C#应用程序传递到IronPython 2.x?谷歌只返回了关于如何使用IronPython1.x的结果 static void Main(string[] args) { ScriptRuntime scriptRuntime = IronPython.Hosting.Python.CreateRuntime(); // Pass in script file to execute but how to pass in other arguments in a
static void Main(string[] args)
{
ScriptRuntime scriptRuntime = IronPython.Hosting.Python.CreateRuntime();
// Pass in script file to execute but how to pass in other arguments in args?
ScriptScope scope = scriptRuntime.ExecuteFile(args[0]);
}
您可以通过以下C#代码设置sys.argv: 具有以下python脚本
import sys
for arg in sys.argv:
print arg
并像调用exe一样调用exe
Test.exe SomeScript.py foo bar
提供输出
SomeScript.py
foo
bar
另一个选项是将准备好的选项传递给
Python.CreateRuntime
,如中所述,1.x解决方案在2.x中不起作用?1.x使用scriptEngine.Sys.argv,它在2.x中被删除。
SomeScript.py
foo
bar