如何在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屋!
查看全文