如何在 IronPython 中传递命令行参数? [英] How can I pass command-line arguments in IronPython?
本文介绍了如何在 IronPython 中传递命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 IronPython 并且以某种方式让它工作.但是,似乎没有将命令行参数传递给 Iron Python 的资源.如何将命令行参数从我的 C# 代码传递给 python 程序?
I am working with IronPython and have got it working somehow. Though, there seems to be no resource on passing command-line arguments to Iron Python. How can I pass command-line arguments to a python program from my C# code?
setup = new ScriptRuntimeSetup();
setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
runtime = new ScriptRuntime(setup);
runtime.IO.RedirectToConsole();
m_engine = runtime.GetEngine("IronPython");
m_scope = m_engine.CreateScope();
source = m_engine.CreateScriptSourceFromString("search_movie.py ""+CommandTextBox.Text+""", SourceCodeKind.InteractiveCode);
source.Execute(m_scope);
我还需要在这里做什么?如您所见,python 文件的名称是 search_movie.py,它以电影名称作为参数.
What more do I need to do here? As you can see, the name of the python file there is search_movie.py and it takes a movie-name as argument.
推荐答案
需要设置sys.argv的值.
You need to set the values of sys.argv.
engine.Sys.argv = List.Make(args);
查看 http://www.voidspace.org.uk/ironpython/custom_executable.shtml 了解更多详情
这篇关于如何在 IronPython 中传递命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文