Interacting with bash from python

前端 未结 4 2015
心在旅途
心在旅途 2020-12-01 14:24

I\'ve been playing around with Python\'s subprocess module and I wanted to do an \"interactive session\" with bash from python. I want to be able to read bash o

4条回答
  •  暖寄归人
    2020-12-01 15:17

    I wrote a module to facilitate the interaction between *nix shell and python.

    def execute(cmd):
    if not _DEBUG_MODE:
        ## Use bash; the default is sh
        print 'Output of command ' + cmd + ' :'
        subprocess.call(cmd, shell=True, executable='/bin/bash')
        print ''
    else:
        print 'The command is ' + cmd
        print ''
    

    Check out the whole stuff at github: https://github.com/jerryzhujian9/ez.py/blob/master/ez/easyshell.py

提交回复
热议问题