Hi.

I am writing a mac program that among other things, allows a user to create unix links to files. Now I am using the runtime.exec() method to run the ls -s command e.g.

ls -s dir1/fileName dir2/NewfileName

This works but becomes difficult if the path name to the file has a space. e.g.

ls -s dir 1/fileName dir2/NewfileName

I thought of moving the file to a central temporary directory then making the unix link then moving them back but in Java there is no real way of moving a file rather it is copying and the unix command mv is also at the mercy of paths with spaces.

Are there any suggestions to overcome this?

Many thanks

Hi,

I was haste in marking as solved.

The idea of enclosing the respective paths in double quotes works when doing directly into the terminal, but from a java program using the
process.exec(command)

I have used single quotes '"' in the program to enclose the path name with the space in double quotes e.g. '"' + pathWithSpace + '"'; the result of which produces the following:

[TEX]ln -s "/Users/cex12/Desktop/eclipse2/features/org.eclipse.datatools.enablement.sap.feature_1.6.1.v200809191145-440_kE77c7QAQEIQQ/epl-v10.html" "/Users/cex12/Desktop/Test Folder/work" which works perfectly directly in the terminal but not so when used in java via the process.exec(command);[/TEX]

Any further help or suggestions would be most welcome.

Oh, I also tried it in single quotes but with the same result.

To get double quotes in a Java String, use the escape character /, ie
"This is called /"Fred/"" -> This is called "Fred".
Single quotes in Java define a char value, so won't be what you need.

This article has been dead for over six months. Start a new discussion instead.