I am using call method to load sql dump:
call(["psql", "-U", "user", "name", "<", "pathtofile"])
This is directly logging into postgres and ignoring "<" and pathtofile.
psql: warning: extra command-line argument "<" ignored
Use stdin
keyword argument if you want redirection:
with open("pathtofile", "rb") as f:
call(["psql", "-U", "user", "name"], stdin=f)
Try changing to this:
call(["psql", "-U", "user", "name", "<", "pathtofile"], shell=True)
^^^^^^^^^^^^
"<" is an input redirection operator, and must be interpreted by a shell. If you don't say shell=True
, it's passed to psql
as an argument, and psql
has no idea what to do with it.
Edit: in general, what @falsetru suggested is a better approach, because passing arbitrary strings to shells can be dangerous. But if you need to use shell operations, shell=True
is the way to do it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.