繁体   English   中英

如何在 python 脚本中运行 postgres 命令并将其写入文件?

[英]How to run a postgres command in python script and write it into a file?

cmd1 = 'psql -h hello.com -p 5433 -U hell_ro-d hello-c \"COPY (SELECT info1,info2,info3,info4 FROM logs_info WHERE info1 > \''+str(timing)+'\' and info1 < clock_timestamp() ORDER BY info1 desc limit 100) TO STDOUT With CSV HEADER\"  > filedetails.csv'

您可以使用 os.system 运行os.system命令:

$ python -c 'from os import system; system("cat >/dev/stderr <<<\"shelly stuff\"")'
shelly stuff

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM