I am working on an issue where spaces in a directory cause a program that runs exp.exe to crash. The user first selects a .dmp file from any directory they want, which is then used to build an argument list. This argument list contains the command to be run, in this case, exp.exe, the .dmp file name, a log file created in the directory the file name comes from, along with some other parameters. ProcessBuilder is then used to do the following:
public static ProcessBuilder build;
build = new ProcessBuilder();
build.command(args);
build.redirectErrorStream(true);
process = build.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
When the directory the file comes from does not have any spaces, exp.exe runs as intended and line prints as expected. However, when the directory the file comes from does contain spaces, exp.exe does not run and terminates after outputting error code LRM-00101: unknown parameter name.
This is an example of a directory that does not work
C:\Users\Me\OneDrive - Folder\Desktop\test\log.dmp
A directory such as that one would be processed incorrectly and output
LRM-00101: unknown parameter name 'Folder\Desktop\test\log.dmp'
And this is an example of a directory that does run
C:\Users\Me\Downloads\test\log.dmp
In the example directory that does not work, ProcessBuilder is incorrectly getting the directory by treating everything before the "- " as not part of the directory, which is causing it to fail. I have already tried to escape the directory with double quotes when it is being read in initially by doing
"\""+dmp_filename+"\""
but that does not work and other suggestions in similar threads do not seem to apply.
This is the exact code for the args being passed in
args = [exp.exe, userid=123@test, buffer=50000000, file=C:\Users\Me\OneDrive - Folder\Desktop\test\log.dmp, owner=test, compress=n, grants=y, indexes=y, direct=no, log=C:\Users\Me\OneDrive - Folder\Desktop\exp_log_test.log, rows=y, consistent=y, object_consistent=y, triggers=y, statistics=none, constraints=y]
I would appreciate any help.