子进程调用在shell和interp中的作用不同

2024-10-03 21:27:58 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python解释器中运行以下命令时,一切正常,但作为脚本运行时失败。不知何故,这条已开放的隧道没有被认出。任何提示都将不胜感激。你知道吗

翻译:

gateway = subprocess.Popen("ssh -N sshgw", shell=True)

scp_prod = "scp -r server:/NFS/{0} .".format(filePath)
subprocess.call(scp_prod, shell=True)

gateway.kill()

脚本:

try:
  gateway = subprocess.Popen("ssh -N sshgw", shell=True)

  scp_prod = "scp -r server:/NFS/{0} .".format(filePath)
  subprocess.call(scp_prod, shell=True)
finally:  
  gateway.kill()

Tags: 脚本trueformatserverprodshellcallssh