【发布时间】:2013-10-24 13:28:25
【问题描述】:
我使用 Bash 脚本。我的 bash 脚本是
#!/bin/bash
function aa(){
echo "Run";
su - postgres -c "shp2pgsql -I -s 4269 /tmp/gismanager/Wards.shp ff | psql postgis;";
echo "Run";
return 0;
}
aa;
当这个脚本由 linux 运行的结果是 Run Run 而从 java 运行的结果是 Run
我的java代码是
public static void execShellCmd(String path) {
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(path);
BufferedReader buf = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = buf.readLine()) != null) {
System.out.println("exec response: " + line);
}
} catch (Exception e) {
System.out.println(e);
}
}
谁能帮帮我?
【问题讨论】:
-
尝试查看这些指向其他 bash/Java 问题的链接 stackoverflow.com/questions/9791251/… stackoverflow.com/questions/10711308/… stackoverflow.com/questions/11955509/…
标签: java bash function postgresql shell