这是我要运行的命令:
su - postgres -c "pg_dump ....."
备份 postgres 数据库。
如果我现在在 linux shell 中,作为 root,它工作得很好。
但是现在,我想从 java 应用程序中运行它,如下所示:
String cmd = "su - postgres -c \"pg_dump --port 5432 .....\""
Process p = Runtime.getRuntime().exec(cmd);
// read the error stream and input stream
p.waitFor();
它抛出一个错误:
su: unknown option "--port"
please try "su --help" to get more information
现在我将代码更改为:
Process p = Runtime.getRuntime().exec(new String[0]{cmd});
// read the error stream and input stream
p.waitFor();
Cannot run program "su - postgres -c \"pg_dump .....\"": java.io.IOException: error=2, no that file or directory
我现在该怎么办?