如何在IronPython/Mono中运行OS shell命令?

Cyb*_*row 5 shell mono ironpython

我想试试IronPython和Mono.具体做sysadmin任务.这通常意味着运行OS命令.在CPython中,我使用子进程模块执行此类任务.但是在IronPython(v2.0.1,Mono 2.4,Linux)中没有子进程模块.似乎甚至没有'os'模块.所以我不能使用os.system().在CPython中,通常使用'subprocess'或'os.system()'的IronPython执行任务的方式是什么?

Cyb*_*row 11

我找到了答案.感谢"IronPython Cookbook".可以在那里找到关于这个主题的更多信息:http: //www.ironpython.info/index.php/Launching_Sub-Processes

>>> from System.Diagnostics import Process
>>> p = Process()
>>> p.StartInfo.UseShellExecute = False
>>> p.StartInfo.RedirectStandardOutput = True
>>> p.StartInfo.FileName = 'uname'
>>> p.StartInfo.Arguments = '-m -r'
>>> p.Start()
True
>>> p.WaitForExit()
>>> p.StandardOutput.ReadToEnd()
'9.6.0 i386\n'
>>> p.ExitCode
0
>>> 
Run Code Online (Sandbox Code Playgroud)