This is the command I want to run:
su - postgres -c "pg_dump ....."
to backup the postgres database.
If I'm in the linux shell now, as a root, it works fine.
But now I want to run it from a java application, like:
String cmd = "su - postgres -c \"pg_dump --port 5432 .....\""
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
Gives an error message:
su: unknown option "--port"
please try "su --help" to get more information
Now I am changing the code as:
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
What should I do now?
source
share