0

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
0

2 Answers 2

2

Use stdin keyword argument if you want redirection:

with open("pathtofile", "rb") as f:
    call(["psql", "-U", "user", "name"], stdin=f)
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.