0

Assume I have

osm2pgsql_proc = sp.Popen(
     [osm2pgsql, "--create", "--database", db_name, 
        "--cache", str(cache_size), "--number-processes", 
        str(osm2pgsql_number_processes), "--slim", "--port", str(db_port), 
        "--host", db_host, "--username", db_user, "--latlong", "--password", 
        "--keep-coastlines", "--extra-attributes", "--hstore-all"]+osm_files, 
    stdin=sp.PIPE)
# tried all of the following alternatives
#osm2pgsql_proc.stdin.write(db_password+"\x1a")
#osm2pgsql_proc.stdin.flush()
#osm2pgsql_proc.stdin.write(db_password+"\n")
#osm2pgsql_proc.stdin.flush()
#osm2pgsql_proc.communicate(db_password+"\x1a")
#osm2pgsql_proc.communicate(db_password+"\n")
#osm2pgsql_proc.stdin.flush()
osm2pgsql_proc.wait()

How do I get past the Password: prompt?

Please notice: I know about pexpect and I can image there might be similar modules, but I'm looking for a solution which also offers a better understanding of subprocess and related concepts of python and OS, Linux respectively, except someone can provide a plausible answer explaining that it doesn't work the way I understand it should to work.

5
  • 1
    related answer Commented Apr 26, 2014 at 23:42
  • the best solution would be to find out whether osm2pgsql supports openssl-like -passin parameter that allows to specify the source for the password (a file, pipe, command-line, envvar, etc) Commented Apr 26, 2014 at 23:46
  • The first link is very useful! I assumed that any input that a program requests can be passed through a pipe, but this is not true (see pexpect.readthedocs.org/en/latest/FAQ.html#whynotpipe (posted in answer in stackoverflow.com/questions/23255708/…)). Now there seems to be no reason not to use pexpect. Thanks again! Commented Apr 27, 2014 at 10:10
  • given that I'm the author of the related answer; you can assume that I've read the link before citing it in my answer. :) Note: you can post your own answer with the pexpect code specific to your case. Commented Apr 27, 2014 at 10:32
  • 1
    You could also implement the solution using pty module directly (you can os.write to master_fd). Commented Apr 27, 2014 at 10:35

0

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.