My goal is to restore a Mysql dump using mysql command.
I'm having a clear difference of behaviour between a code using ProcessBuilder and Apache Commons Exec (1.3).
This code works perfectly fine
List<String> params = new ArrayList<>();
params.add("sh");
params.add("-c");
params.add("mysql -uroot -proot < /tmp/the_dump.sql");
ProcessBuilder pb = new ProcessBuilder(params);
Process p = pb.redirectErrorStream(true).start();
int exitValue = p.waitFor();
But this one (with Apache Commons Exec)
CommandLine cmdLine = new CommandLine("/usr/bin/sh");
cmdLine.addArgument("-c");
cmdLine.addArgument("mysql -uroot -proot -e 'source /tmp/the_dump.sql'");
PumpStreamHandler streamHandler = new PumpStreamHandler(System.out, System.err, System.in);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(streamHandler);
int exitValue = executor.execute(cmdLine);
crashed with the following error :
Note the missing ' at the end of the command as interpreted by Apache Commons Exec.
Does anyboday has an idea how to make it work with Apache Commons Exec ?
Thanks a lot for your help, Sylvain