我想执行这个命令
D:/Projects/GDAL/ogr2ogr.exe -f "MapInfo File" D:/Projects/GDAL/r/output_test.tab PG:"host=localhost user=postgres password=123456 dbname=postgis" -sql "SELECT * from filedata WHERE num=1"我试过这个:
Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "D:/Projects/GDAL/ogr2ogr.exe -f \"MapInfo File\" D:/Projects/GDAL/r/output_test.tab PG:\"host=localhost user=postgres password=123456 dbname=postgis\" -sql \"SELECT * from filedata WHERE num=1\""});我没有收到错误,但是什么也没有发生。我的错误在哪里?
发布于 2012-08-09 19:49:17
您应该添加'/C':
Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "D:/Projects/GDAL/ogr2ogr.exe -f \"MapInfo File\" D:/Projects/GDAL/r/output_test.tab PG:\"host=localhost user=postgres password=123456 dbname=postgis\" -sql \"SELECT * from filedata WHERE num=1\""})发布于 2012-08-09 19:40:35
请阅读以下内容:http://www.javaworld.com/jw-12-2000/jw-1229-traps.html,一步一步地浏览每个建议。
Process API因容易出错而臭名昭著。
发布于 2012-08-09 19:53:49
尝试检查返回值:
String command = ""; // Your command
Process installproc = installcommand.execute();
StringBuilder out = new StringBuilder();
StringBuilder err = new StringBuilder();
installproc.waitForProcessOutput(out, err);
if (out.length() > 0) System.out.println("out:\n$out".toString());
if (err.length() > 0) System.out.println("err:\n$err".toString());
if(installproc.exitValue() != 0) {
throw new Exception("");
}这只是示例代码,我没有以任何方式对其进行测试。
这应该会给出一些关于错误的提示。
https://stackoverflow.com/questions/11882489
复制相似问题