我写了一个名为 load_data.exp 的 expect 脚本
#!/usr/bin/expect
spawn "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm"
expect "Password:" {send "mysecretpassword"}
更改权限
chmod +x load_data.exp
运行它
./load_data.exp
文件确实存在,它给我错误
spawn osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
couldn't execute "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm": no such file or directory
while executing
"spawn "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm""
(file "./load_data.exp" line 6)
osm2pgsql已经安装好,可以直接在terminal下一句运行
osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
我猜spawn有问题
最佳答案
正如错误提示的那样,它试图找到一个不叫 osm2pgsql
的程序,而是一个叫 osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore/absolute/path/to/bruges_belgium.osm
包括所有空格和破折号作为可执行文件名称的一部分。从 spawn 命令中删除引号:
spawn osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
关于Linux expect spawn找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32585342/