0
votes

I'm trying to execute a SAS code with VBScript through the command line. However, I'm having issues with passing the commands from VBScript to command line properly. I'm pretty sure it is a matter of using quotes and chr(34) correctly, but I cannot figure it out.

So I want to run the follow command in command line:

"C:\Program Files\SAS 9.4\sas.exe" -SYSIN "C:\Program Files\test.sas"

I've tried something like

Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K copy ""C:\Program Files\SAS 9.4\sas.exe"" -SYSIN ""C:\Program Files\test.sas"" ", 1, True
Set oShell = Nothing

But I get an invalid syntax error in command line. Any good ideas?

1

1 Answers

1
votes

CMD /K expects a single argument. If the argument contains spaces, the argument must be quoted. So the full command would be something like:

oShell.run "cmd.exe /K "" ""C:\Program Files\SAS 9.4\sas.exe"" -SYSIN ""C:\Program Files\test.sas"" "" ", 1, True

Normally, one would have to worry about nested quoting/escapes, but the /C and /K switches are special in how quotes work (CMD /? explains the details). If it looks like a single quoted argument, any quotes inside are automatically ignored by CMD.