所以我写了一个脚本,在命令行上使用nc访问一堆服务器,最初我使用Python的命令模块并调用commands.getoutput(),脚本在大约45秒内运行.由于命令已弃用,我想将所有内容更改为使用子进程模块,但现在脚本需要2m45s才能运行.任何人都知道为什么会这样?
我之前的所作所为:
output = commands.getoutput("echo get file.ext | nc -w 1 server.com port_num")
Run Code Online (Sandbox Code Playgroud)
我现在有
p = Popen('echo get file.ext | nc -w 1 server.com port_num', shell=True, stdout=PIPE)
output = p.communicate()[0]
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!