B4J Question Whitespace in Shell WorkingDirectory on Mac OS X

b4x-de

Active Member
Licensed User
Longtime User
Hello,

I struggle with a path like /Users/user1/Library/Application Support/b4j.example/test to set it as shell working directory.

I tried to use it like above or to escape whitespaces:

B4X:
    Dim sh1 As Shell
    sh1.Initialize("Test", "<some command>", Null)
    sh1.WorkingDirectory = "/Users/user1/Library/Application Support/b4j.example/test" ' does not work
    sh1.WorkingDirectory = "/Users/user1/Library/Application Support/b4j.example/test".Replace(" ", "\ ") ' does not work
    sh1.WorkingDirectory = """/Users/user1/Library/Application Support/b4j.example/test""" ' does not work

The result is always the same when I execute the shell command:

B4X:
java.io.IOException: /Users/user1/Library/Application Support/b4j.example/test" doesn't exist.

Does anyone know how to handle whitespace in a path to use with shell working directory?

Thanks,
Thomas
 

OliverA

Expert
Licensed User
Longtime User
Try using a backslash before the whitespace
 
Upvote 0

b4x-de

Active Member
Licensed User
Longtime User
Try using a backslash before the whitespace

Thanks, but this was above option #2. It does not work:

B4X:
sh1.WorkingDirectory = "/Users/user1/Library/Application Support/b4j.example/test".Replace(" ", "\ ") ' does not work
 
Upvote 0

b4x-de

Active Member
Licensed User
Longtime User
I can execute the same line from terminal window without any problems. The code above also works well from a directory that does not contain any whitespace.
 
Upvote 0

b4x-de

Active Member
Licensed User
Longtime User
It turned out the error message was missleading. There was no problem with whitespaces in path but with a permission on a subfolder.

Thanks a lot for everyone helping me with this problem. To sum up: You don't need to escape whitespaces in a path at all when using a shell to execute commands. Whitespaces causing no problem at all.

If you want to escape whitespaces on OS X you may:
a) use quotes, i.e. "/Users/user1/Library/Application Support/b4j.example" (in B4x """")
b) user single quotes, i.e. 'Users/user1/Library/Application Support/b4j.example'
c) escape whitespaces, i.e. Users/user1/Library/Application\ Support/b4j.example

Thanks a lot to everyone, helping
Thomas
 
Upvote 0
Top