How to run OS shell commands in IronPython / Mono?

I would like to try IronPython and Mono. Specifically performing sysadmin tasks. This often means executing OS commands. In CPython, I use a subprocess module for such tasks. But in IronPython (v2.0.1, Mono 2.4, Linux) there is no subprocess module. It seems that there is not even an os module. Therefore I can not use os.system (). What will be the IronPython method to accomplish the tasks you usually use for the subprocess or os.system () for CPython?

+4
source share
4 answers

I have found the answer. Thanks to the "Cookbook" IronPython. Here you can find additional information on this subject: 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 >>> 
+10
source

You can use most of the standard os modules from within ironpython.

 import sys sys.path.append path('...pathtocpythonlib......') import os 
+1
source

Consider this C # Interactive Shell too ... not sure if it supports IronPhython in the shell, but Mono does, as you know.

0
source

The implementation of a partial subprocess module is implemented here:

http://www.bitbucket.org/jdhardy/code/src/tip/subprocess.py

The module (at this time, June 2010) only supports the redirection of STDIO pipes (like, you cannot provide your own files-like objects that must be filled with the output or intput stream), but the basics are enough to get the path.

0
source

All Articles