2024-04-19 20:58:44 发布
网友
我有一个python日志分析程序。 该日志位于另一个具有端口号和密码的服务器中。你知道吗
我无法将python代码存储在该服务器中。所以我需要scp文件到服务器,我的程序存储。你知道吗
我做到了:
popen('''sshpass -p "password" scp -r \ admin@192.158.11.109:/home/admin/DontDeleteMe/%s /home/admin/''' % fileName)
但如果文件很大,程序将在完成复制过程之前运行。你知道吗
popen()不等待进程完成。您可以使用subprocess.call():
popen()
subprocess.call()
exitcode = subprocess.call('''sshpass -p "password" scp -r \ admin@192.158.11.109:/home/admin/DontDeleteMe/%s /home/admin/''' % fileName, shell=True)
根据Python的doc:
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:os.system os.spawn* os.popen* popen2.* commands.*
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:
subprocess
os.system os.spawn* os.popen* popen2.* commands.*
popen()
不等待进程完成。您可以使用subprocess.call()
:根据Python的doc:
相关问题 更多 >
编程相关推荐