Fork me on GitHub

版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | https://vearne.cc
import subprocess
# print ’popen3:’
def external_cmd(cmd, msg_in=''):   
    try:       
        proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,)        
        stdout_value, stderr_value = proc.communicate(msg_in) 
        return stdout_value, stderr_value    
    except ValueError, err: 
        # log("IOError: %s" % err)       
        return None, None

if __name__ == '__main__':    
    stdout_val, stderr_val = external_cmd('ls -l')    
    print 'Standard Output: %s' % stdout_val    
    print 'Standard Error: %s' % stderr_val

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据