Solved Batch file file path problems

January 12, 2013 at 16:50:24
Specs: Windows 7, Core2duo 2ghz / 4G
I've got a batch file setup whereby a master batch calls several slave batches to install programs. Most of them work fine, but the ones where I must use quotes because of spaces in the file path are not working.

If I don't enclose the file path in quotes, I get a path error, of course.
If I enclose the path in quotes, I get a switch error "/S: invalid switch". But /S is a valid switch.
If I enlarge the quotes to include the switches also, the master batch spawns a separate CMD window which sits there doing nothing. When I finally close it out the master batch asks me if I want to terminate the master batch process.

If I go directly into the folder with a CMD window and fire the sub batch with the /S switch, it works fine. So somewhere I am missing something regarding processing. Any insight would be appreciated.

Thanks,
p.


See More: Batch file file path problems

Report •


✔ Best Answer
January 13, 2013 at 06:57:20
I'm no batch file expert but I think that when there is a Start command it sees the first item in quotes as a name.

Try using double quotes (no name) ahead of the path, like this:

start /wait "" "%drive%:\pctools\enhancements\system\7z920.exe" /S /d="c:\program files\7zip"

I got caught out by this way back.

Always pop back and let us know the outcome - thanks



#1
January 12, 2013 at 16:53:06
So somewhere I am missing something
Like posting the batch file you're asking about?

How To Ask Questions The Smart Way


Report •

#2
January 12, 2013 at 18:37:11
You do have the option of navigating to the "spaces in path" subdirectory using either cd or pushd. But I, too, am awaiting further enlightenment as to the configuration of your setup. Esp. the primary batch, and an example of a failed "call" and the target script.

followup: was going to suggest shortnames, but after looking, win-7 doesn't seem to support them. I hate win-7etc(8,9,10...)


Report •

#3
January 12, 2013 at 18:49:03
Ok. I already moved everything to one folder and changed the batches to eliminate the problem, but I'd rather solve it the right way.

Here's what it used to look like:

The master batch would be in <usb drive>\pctools\enhancements\apps:

echo.
set /p drive="enter root drive of the install batch file:  "
%drive%:
cd "pctools\enhancements\apps"
call _7zip.bat

_7zip.bat would be in the same folder:

start /wait "%drive%:\pctools\enhancements\system\7z920.exe" /S /d="c:\program files\7zip"

But I tried other permutations in the slave batches, as I wrote in my OP - expanding the quotes or CDing over to the target folder first instead of using the long filespec in the Start command - with all of them running into various problems.

I've even run into problems with quotes when the target executable is in the same directory. For example,

mse32.exe" /s 

would run into problems, but eliminating the quotes would solve them. I have no idea why that is the case.


Report •

Related Solutions

#4
January 13, 2013 at 06:57:20
✔ Best Answer
I'm no batch file expert but I think that when there is a Start command it sees the first item in quotes as a name.

Try using double quotes (no name) ahead of the path, like this:

start /wait "" "%drive%:\pctools\enhancements\system\7z920.exe" /S /d="c:\program files\7zip"

I got caught out by this way back.

Always pop back and let us know the outcome - thanks


Report •

#5
January 13, 2013 at 07:17:43
If this script intends to install 7-zip, it would crash and burn on my system. I currently do not have a C: drive. I'd fix it, but bad programmers make bad programs, and bad programmers assume "C:\Program Files", so I can keep whole classes of bad programs off of my PC by not fixing anything.

I used to also have a PC with Spanish installed as the default language, so your script would have crashed and burned on that one as well.

How To Ask Questions The Smart Way


Report •

#6
January 13, 2013 at 07:27:37
Thanks, Derek. I definitely will look into that. I actually did have blank quotes in my earlier attempts, but removed them when I saw in MS help that they looked optional and there was no warning in the Notes:

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
      [command/program] [parameters]

    "title"     Title to display in window title bar.
    path        Starting directory.

You may be onto something.


Report •

#7
January 13, 2013 at 07:47:03
Derek, it looks like you nailed it. Adding empty quotes allowed me to access the 7zip installer in a different folder, and windows recognized the /S switch as valid. Thanks much!

Report •

#8
January 13, 2013 at 09:21:06
Glad to hear it and thx for popping back to let us know.

Always pop back and let us know the outcome - thanks


Report •


Ask Question