-1

In the following script:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%comspec% /k" & _
    " ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe"" " & _
    "move ""C:\Automation\Custom_UiPath_Activities\NuPackages\*.nupkg"" ""C:\Automation\Custom_UiPath_Activities\NuPackages\Old""", 1, True

it gives the error

'C:\Program' is not recognized as an internal or external command.

Seemingly because the escaped quotes around the first argument is ignored. I've tried logging the string to a text file, and when copying the outputted string into CMD it works as intended.

I cannot see what I have done wrong.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

1 Answers1

0

If you want to daisy-chain commands in CMD you need to put an ampersand (&) between them as part of the commandline. Your code is using the ampersand just as the VBScript string concatenation operator. Also, for running multiple commands via cmd /k (or cmd /c) you need to put an additional set of double quotes around them. Also, using variables and a quoting function helps with keeping your code readable.

Function qq(s) : qq = """" & s & """" : End Function

tf = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.exe"
src = "C:\Automation\Custom_UiPath_Activities\NuPackages"
dst = "C:\Automation\Custom_UiPath_Activities\NuPackages\Old"

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run "%comspec% /k """ & qq(tf) & " & " & _
    "move " & qq(src & "\*.nupkg") & " " & qq(dst) & """", 1, True
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328