我使用 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);
}
}
有谁能够帮我?