以编程方式输入osm2pgsql密码

2024-09-22 14:30:09 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有

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()

如何通过Password:提示?在

请注意:我知道pexpect,我可以想象可能有类似的模块,但我正在寻找一种解决方案,它可以更好地理解python和OS、Linux的子进程和相关概念,除非有人能提供一个合理的答案来解释它没有按照我所理解的方式工作。在


Tags: hostnumbercachedbportstdinpasswordproc