7

I'm missing something (obvious?) about escaping my strings or spaces in the following Windows Server 2k3 batch command.

FORFILES -m *.wsp -c "CMD /C C:\Program^ Files\Common^ Files\Microsoft^ Shared\web^ server^ extensions\12\bin\stsadm.exe^ -o^ addsolution^ -filename^ @FILE"

Results in the following error

'C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe -o addsolution -filename "foobar.wsp"' is not recognized as an internal or external command,operable program or batch file.

But I can't figure out why. I'm working off Mr. Simon Sheppard's fine documentation

double-beep
  • 5,031
  • 17
  • 33
  • 41
Noel
  • 2,061
  • 4
  • 31
  • 47
  • Closely related: [How do you run a command with a full path from the Windows forfiles command?](https://stackoverflow.com/q/39452239) – aschipfl Jan 20 '22 at 10:03

2 Answers2

10

The path needs to be quoted, and the quote must be escaped.

FORFILES -m *.wsp -c "CMD /C ^0x22C:\Program^ Files\Common^ Files\Microsoft^ Shared\web^ server^ extensions\12\bin\stsadm.exe^0x22 -o^ addsolution^ -filename^ @FILE"

A co-worker suggested using the hex for ", and I eventually figured out that the hex needed escaping.

Noel
  • 2,061
  • 4
  • 31
  • 47
2

Another possible answer is to use the old 8.3 names you get by doing dir /X.

Like: C:\PROGRA~1 instead of C:\Program Files.