I'm trying to use java to run a system command to load a sqlite3 database from a sql file. There is no error in the sql file, it loads ok using the usual method from the command line:
sqlite3 dbname < file.sql
My method:
public void loadSqlFile(String file, boolean tearDown) {
String s = null;
try {
Process p = Runtime.getRuntime().exec(
"/usr/bin/sqlite3 " +
database +
" < " +
file
);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
} catch (IOException e) {
LOGGER.error("Failed to load sql file (" + file + ")");
} catch (InterruptedException e) {
LOGGER.error("Failed to load sql file (" + file + ")");
}
}
The command being run translates to:
/usr/bin/sqlite3 /tmp/infinite_state_machine_root/1535223603610/control/database/ism.db < /tmp/ISMCoreActionPack_sqlite3.sql
And the error I see on stdout is:
Error: near "<": syntax error
I've searched for a lot of examples of running system commands and can't find anything that explains this error, at least to me!
I have tried other commands in there like ps and so on and they seem to run ok.
Any advice?
I'm running this on a MAC if that is significant.