【发布时间】:2015-07-15 14:09:08
【问题描述】:
我正在尝试使用给定的特定命令从数据库中转储信息。
db_dump = open('{}/dbdump.txt'.format(directory_name), 'w+')
foo = subprocess.call('PGPASSWORD="-------" pg_dump -h vm-postgres -d "qa-test{}db" -U "qatest" -a -x'.format(str(driverlabelnum)), shell=True)
print str(foo)
db_dump.write(foo)
db_dump.close()
print "Done dumping"
当我将它复制粘贴到命令行时它工作得很好,但是当我尝试通过 subprocess.call() 自动化它时出现错误。
我尝试了几种不同的方法,但我一直遇到这个错误......
Traceback (most recent call last):
File "/home/csd-user/test/libs/utils/butler.py", line 427, in <module>
main()
File "/home/csd-user/test/libs/utils/butler.py", line 424, in main
b.log_bug_exec(url)
File "/home/csd-user/test/libs/utils/butler.py", line 52, in log_bug_exec
cls.process_file(stdout)
File "/home/csd-user/test/libs/utils/butler.py", line 109, in process_file
cls.create_artifacts(nums[0], nums[1])
File "/home/csd-user/test/libs/utils/butler.py", line 269, in create_artifacts
foo = csd_shell_lib.check_output('PGPASSWORD="-------" pg_dump -h vm-postgres -d "qa-test{}db" -U "qatest" -a -x'.format(str(driverlabelnum)))
File "/home/csd-user/test/libs/jupiter/csd_shell_lib.py", line 70, in check_output
return subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
File "/opt/cs/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/opt/cs/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/cs/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我知道 subprocess.call 命令将命令拆分为substrings(.split(' ')) 的数组/列表,并且它本身正在调用 PGPASSWORD=""。但是,我不知道如何避免这种情况发生,也无法在网上找到。
附:我遇到的另一个问题是 Errno 13 权限被拒绝,Paramiko 试图 .get 一个文件。我不知道/理解如何在没有程序提示我输入密码的情况下以su 或sudo 登录(仅使用单数 paramiko 命令)(我可以使用 ssh 来完成,但我不想这样做) .
【问题讨论】:
-
什么是完整的回溯?
标签: python linux bash subprocess paramiko