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.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • 1
    [related answer](http://stackoverflow.com/a/23257657/4279) – jfs Apr 26 '14 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) – jfs Apr 26 '14 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 http://pexpect.readthedocs.org/en/latest/FAQ.html#whynotpipe (posted in answer in http://stackoverflow.com/questions/23255708/automate-stdin-with-python-using-stdin-write)). Now there seems to be no reason not to use pexpect. Thanks again! – Kalle Richter Apr 27 '14 at 10:10
  • given that I'm the author of [the related answer](http://stackoverflow.com/a/23257657/4279); you can assume that I've read [the link](http://pexpect.readthedocs.org/en/latest/FAQ.html#whynotpipe) before citing it in my answer. :) Note: [you can post your own answer](http://stackoverflow.com/help/self-answer) with the `pexpect` code specific to your case. – jfs Apr 27 '14 at 10:32
  • 1
    You could also implement the solution [using `pty` module directly](http://stackoverflow.com/a/22253472/4279) (you can `os.write` to `master_fd`). – jfs Apr 27 '14 at 10:35

0 Answers0