From: doodpants@... (Karl von Laudermann) Date: 2004-10-29T02:29:00+09:00 Subject: Execution and dos path woes Is there an easy way in Ruby to convert a long dos path name into a short path name, so as to eliminate spaces in the path? I've encountered what may be a bug in Ruby, or perhaps a limitation in how it communicates with the system in dos/Windows. I'm using the backquote string to execute programs externally. I want to be able to execute the program without adding its directory to the system path, so I must call it with a full path name. Now, dos requires you to put a path in quotes if it contains spaces. So if I try to run `C:\Documents and Settings\kvonlaudermann\My Documents\foo.exe` I get the error: 'C:\Documents' is not recognized as an internal or external command, operable program or batch file. But If I run `"C:\Documents and Settings\kvonlaudermann\My Documents\foo.exe"` It will work fine. Now, suppose I want to pass in another file as a parameter to the executable. If the file is in the current directory, I can do this: `"C:\Documents and Settings\kvonlaudermann\My Documents\foo.exe" foo.cfg` But I actually want to specify the full path to the config file, which may have spaces, so I need to put it in quotes as well: `"C:\Documents and Settings\kvonlaudermann\My Documents\foo.exe" "C:\Documents and Settings\kvonlaudermann\My Documents\foo.cfg"` Oddly enough, this doesn't work; I get the same error message as in the first example: 'C:\Documents' is not recognized as an internal or external command, operable program or batch file. It's as though the second quoted string causes the system to ignore the first set of quotes. Also, if I type this in manually at a dos command prompt, it works; it only fails when being called from a Ruby script. So it seems my options are: - Find a way, either via a Ruby library method or a dos command, to convert a long path into a short path, so that I don't have to use quotes. - Change the working directory to the executable's directory so that I don't have to specify a path and quote the executable name. - Change the working directory to the file's directory so that I don't have to specify a path and quote the config file name. I'm running Ruby 1.8.1 on Windows XP, BTW. Any thoughts?