1

我想执行这个命令

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\""});

我没有错误,但什么也没发生。我的错误在哪里?

4

3 回答 3

4

阅读此内容:http ://www.javaworld.com/jw-12-2000/jw-1229-traps.html并逐步完成每个建议。

Process API 因陷阱而臭名昭著。

于 2012-08-09T11:40:34.793 回答
1

你应该添加'/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-09T11:49:16.610 回答
0

尝试检查您的返回值:

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("");
}

这只是示例代码,我没有以任何方式对其进行测试。

这应该你给出一些关于错误是什么的提示。

于 2012-08-09T11:53:48.540 回答