2016-02-26 83 views
0

我在執行我們的一個devops腳本時遇到了一個錯誤。該腳本使用sh軟件包(用於執行常見的unix命令,pypi link)。但是,執行的命令在由sh打印的消息中被截斷。我怎樣才能看到執行的整個命令?如何使用sh模塊執行完整的命令?

例如:

import sh 
sh.ssh(host, 
     'rsync -av {src} {dst}'.format(src=src, 
             dst=dst), 
     _out=sys.stdout 
    ) 

生成輸出,如:我想

INFO:sh.command:<Command '/bin/ssh [email protected](77 more)' call_args {'bg': False, 'timeo...(522 more)>: starting process 

看到完整的命令執行,所有的call_args的。

回答

1

sh.ssh返回sh.RunningCommand對象,您可以查詢到找到調用了args和CMD:

import sh 
a=sh.ssh(host, 
     'rsync -av {src} {dst}'.format(src=src, 
             dst=dst), 
     _out=sys.stdout 
    ) 
print(a.cmd) 
print(a.call_args)