我正在尝试从多个.pbf文件创建一个SQL表。
我正在使用osm2pgsql将文件加载到远程数据库中,并尝试使用python和pexpect自动执行该过程。
虽然第一个osm2pgsql命令成功运行,但是在打印“使用PBF解析器”之后,后续命令似乎卡住了。
这是我的代码:
child = pexpect.spawn('bash',timeout=20000)
child.logfile_read = sys.stdout.buffer # show output for debugging
filenames = os.listdir('pbf_files')
for i,filename in enumerate(filenames):
print(filename)
upload_command_args = [
"pbf_files/{}".format(filename),"-l","-s","-d",db_name,"-U",username,"-P",port,"-H",host,"-W","-S","default.style","-r","pbf","-p",table_name,"--hstore",]
# Need the append option since table already exists after first iteration
if i > 0:
upload_command_args = upload_command_args + ["--append"]
print(upload_command_args)
child.sendline('osm2pgsql ' + ' '.join(upload_command_args))
child.expect('Password:')
child.sendline('myFakePass')
child.expect('Osm2pgsql took .+ overall')
child.close()
sys.exit(child.status)
第0次迭代正常运行,但第1次迭代在shell打印后卡住了:
Reading in file: pbf_files/my_partition_1.pbf
Using PBF parser.
我误解了.expect()的工作原理吗?