0

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.

1 Answers1

0

Spaces in file or directory names have to escape by \!

String file = "C:\Users\Me\OneDrive - Folder\Desktop\test\log.dmp";
file  = file.replaceAll(" ", "\\ ");

The double escaping isn't really nice!

Thilo Schwarz
  • 640
  • 5
  • 24
  • I replaced the spaces with a \ as you mentioned, although I had to do it by doing replaceAll(" ","\\\\"). When doing this though, I am getting a new error EXP-00028: failed to open C:\Users\Me\OneDrive-\Folder\Desktop\test\exp_log.log for write. Would you happen to know why when running exp.exe the \ before the - is cut off? I am creating the directory if necessary but that directory is created as C:\Users\Me\OneDrive\-\Folder\Desktop\test, so I am not sure why that \ is cut off before the - when attempting to write to it. – binarycoffee356 Jan 11 '22 at 18:29
  • 'faild to open for write' sound like a permission problem. Whitespaces in file paths are problematic on all platforms. The File object is handling whitespaces correct. But you are a level deeper lower because you are using the Processbuilder! So you have to have to handle whitespaces yourself! Did you try your call on commandline? That offen helps to find out the correct escaping. – Thilo Schwarz Jan 11 '22 at 19:38
  • By "failed to write," it meant that it failed to write because the directory did not exist. For some reason the first "\" was cut off before the "-" in the name. I decided to strip the file name of all whitespace and replace it with an empty string, create the directory if it didn't exist, which it should not the first time, and then create the log.dmp file in the new directory if it does not already exist. That seemed to get it to work, although I had to create a new directory to do so. I would have wanted to just be able to pass in the file name with the space in it. – binarycoffee356 Jan 11 '22 at 23:06