Page 1 of 2

VBoxManage and filesnames with whitespaces

Posted: 17. Oct 2011, 14:04
by kasi
I can't seem to pass filenames with a whitespace to vbox through vboxmanage. For example this doesn't work:

Code: Select all

 VBoxManage guestcontrol  win7 execute --username u --password u --image "c:\\windows\\system32\\cmd.exe" -- "/c" "start" "\\\\VBOXSVR\\ws\\a file.xlsx"
It seems that somewhere along the way, the parameters get lost. It works well for filenames without spaces.

Any ideas how I can get this working?

Thanks.

PS: This also doesn't work

Code: Select all

 VBoxManage guestcontrol  win7 execute --username u --password u --image "c:\\windows\\system32\\cmd.exe" -- "/c" "start" "\\\\VBOXSVR\\ws\\a\ file.xlsx"
VBoxManage guestcontrol  win7 execute --username u --password u --image "c:\\windows\\system32\\cmd.exe" -- "/c" "start" "\\\\VBOXSVR\\ws\\a\\ file.xlsx"

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 13:08
by mpack
Why are you doubling up the path separators? This is a command line, not a string in a C source file.

Also, please don't say "doesn't work". Give specific error messages or symptoms.

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 16:04
by kasi
Even with single path separators, it doesn't work.

What I mean by 'it doesn't work" is that Windows opens the cmd line, seems to execute the 'start' command, but doesn't actually open the file. In the example I gave, it doesn't start Excel to open the file 'a file.xlsx'. If I rename the file to not have the whitespace in it's name, then it'll work.

An interesting thing is that the cmd shell in Windows stays open, although I pass the /c parameter. This might mean that the start command hasn't completed.

Does it work for you? It's every easy to test. Just create a text file with a whitespace on a shared directory and then try to open it with the command I gave.

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 16:27
by Etepetete
According to your profile, you have an Ubuntu host. The VBoxManage command has to be run on your host and not in the VM. You need to use the typical syntax for your host.

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 16:50
by kasi
I run it on the host. I just mount the local directory as a transient shared directory in the guest (windows) and then want to open a file on that shared directory in the guest.

For this, I need to send the command to the guest via vboxmanage to open that particular file. That doesn't work with filenames that have spaces.

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 17:15
by Etepetete
Okay, then try putting the file name which has a space in it also within "".

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 17:34
by kasi
Using "" inside unfortunately doesn't help. I tried the following things:

Code: Select all

"c:\windows\system32\cmd.exe"  -- "/c" "start" '\\VBOXSVR\ws\a file.xlsx"
"c:\windows\system32\cmd.exe"  -- "/c" "start" '"\\VBOXSVR\ws\a file.xlsx""
"c:\windows\system32\cmd.exe"  -- "/c" "start" '\"\\VBOXSVR\ws\a file.xlsx\"'
I also tried using the powershell without success:

Code: Select all

"c:\windows\\system32\windowspowershell\v1.0\powershell.exe" -- 'start-process \\VBOXSVR\ws\a file.xlsx'
"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -- 'start-process "\\VBOXSVR\ws\a file.xlsx"'
"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -- 'start-process \"\\VBOXSVR\ws\a file.xlsx\"'
Again, opening a file is working as long as the file has no whitespace in its filename:

Code: Select all

"c:\windows\system32\cmd.exe"  -- "/c" "start" '\\VBOXSVR\ws\a-file-without-spaces.xlsx"
"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -- 'start-process \\VBOXSVR\ws\a-file-without-spaces.xlsx'
These seems to be something weird going on when calling vboxmanage from a bash in Linux.

Re: VBoxManage and filesnames with whitespaces

Posted: 18. Oct 2011, 18:09
by Etepetete
What happens if you pass the following command sequence on your host?

Code: Select all

VBoxManage guestcontrol  win7 execute --username u --password u --image "c:\windows\system32\cmd.exe" -- /c start "\\VBOXSVR\ws\"a file.xlsx""

Re: VBoxManage and filesnames with whitespaces

Posted: 22. Oct 2011, 15:29
by kasi
That unfortunately doesn't work, because in this case the VBoxManage somehow converts the \" sequence into \\\ on the host.

It's really weird that nobody ever tried to send a file for editing to a vbox windows guest. Most people on Linux would need this for, for instance, MS Office files. (I know there's OO, but it doesn't have all the necessary compatibility)

Re: VBoxManage and filesnames with whitespaces

Posted: 22. Oct 2011, 17:35
by Perryg
What happens if you just wrap the file name and extension? Not the entire string.

Re: VBoxManage and filesnames with whitespaces

Posted: 22. Oct 2011, 17:39
by mpack
This would be my bash at the correct syntax for a Linux host :-

Code: Select all

VBoxManage guestcontrol  win7 execute --username u --password u --image "c:\windows\system32\cmd.exe" -- /c start """\\VBOXSVR\ws\a file.xlsx"""
The things to note are the outer wrapper, i.e. "a b c d" causes the string inside to be treated as a single input by VBoxManage. If the string inside includes quotes then those need to be doubled up: VBoxManage should parse them and pass them along as single quotes in the cmdline of the called program.

Re: VBoxManage and filesnames with whitespaces

Posted: 24. Oct 2011, 01:12
by kasi
Triple quote can't work, because the bash parser always matches pairs of ".

Just to be sure, I tested it and it doesn't work. Any other suggestions? Nobody ever tried to send a parameters with a whitespace to vbox via vboxmanage?

Re: VBoxManage and filesnames with whitespaces

Posted: 24. Oct 2011, 02:29
by Perryg
Did you try what I suggested? "a file.xlsx"
In Linux if there are no spaces you don't need the dbl ticks.
And to answer your question, no very few that work in the Linux CLI use spaces. We may be lazy but the thought of having to type the " " is not appealing.

Re: VBoxManage and filesnames with whitespaces

Posted: 25. Oct 2011, 15:15
by mpack
kasi wrote:Triple quote can't work, because the bash parser always matches pairs of ".
Out of curiosity I just tried writing a command line parser function that worked the way I suggested... and quickly found myself climbing up my own posterior, so I guess that wasn't a good suggestion! Problem was infinite lookahead potentially required to resolve possible ambiguities.

The only set of rules I was able to implement without it becoming needlessly complicated was variations on what has already been discussed in this thread, i.e. arguments which need to be quoted (because they contain spaces) can be bracketed with either " or '. If the bracketed string must contain the qoute char then all occurrences of that char must be escaped with \.

So: "x y z" or 'x y z' are valid ways to bracket strings containing spaces, but no quote chars.
"x ' z" or 'x " z' is one way you can include quote chars without confusing the parser.
"x \" ' z" works when you can't avoid embedding a char that matches the quote char.

In fact it's possible to come up with an even simpler variant in which " is the only allowed quote char, and all embedded occurrences must be escaped... but if it was me I would implement the choice of quote chars for elegance, and because it costs almost nothing in code terms.

That makes my next suggestion :-

Code: Select all

VBoxManage guestcontrol  win7 execute --username u --password u --image "c:\windows\system32\cmd.exe" -- /c start
"\"\\VBOXSVR\ws\a file.xlsx\""
Which (I've just checked) does not exactly match any suggestion already given.

Note that the escape char \ is not generic. Only a limited number of \x sequences would be supported (i.e. only \quotechar), anything else passes through unmodified, otherwise it makes a mess of Windows pathnames (we're back to having to use \\ for all path separators). And \ would certainly be the escape char I'd use.

Re: VBoxManage and filesnames with whitespaces

Posted: 3. Nov 2011, 04:50
by kasi
Unfortunately none of the variations given and also the last suggestion to quote the \" doesn't work. There seems to be a problem with the way that vboxmanage passes on the parameters to vbox. It's really a pity and I wonder whether anyone has ever tried to pass parameters with spaces, because it seems to give problems.