I can run the following via bash and it will work:
psql -h <host> -p <port> -d <dbname> -U <username> -w -v username="'user'" -v rid=2 -c '\ir ../../../resources/sql/myFile.sql'
When I try to run the command in Java using the following, it doesn't do anything but it doesn't throw an error either. Is there a way I can log what the exec in Java is doing so I can see why it isn't working?
try {
String line;
log.error("Working Directory = " +
System.getProperty("user.dir"));
Process p = Runtime.getRuntime().exec("psql -h <host> -p <port> -d <dbname> -U <username> -w -v username=\"'user'\" -v " +
"rid=2 -c '\\ir sql/myFile.sql'");
log.error("HERE");
BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
log.error(line);
}
input.close();
log.error("here2");
} catch (Exception e) {
log.error("Error occurred" + e.toString());
}
HERE and here2 print out to the console, but nothing in Error occurred.
The process exit value is 1.