0

I am new to creating Windows Script Host Scripts.

The script shown below creates an empty Output.txt file. Does anyone see anything wrong with the script?

Set WshShell = WScript.CreateObject("WScript.Shell")
Dim exeName 
Dim statusCode
strCommand = "C:\Program Files\TortoiseSVN\bin\svn.exe info ""C:\Users\Me\Desktop\MyRepo""" & "> C:\Users\Me\Documents\Output.txt"
WshShell.Run "%comspec% /c " & strCommand, 1, True
MsgBox("End of Program")

Update: As mentioned in the comments below, my issue was with not recognizing a path having a space needs to be quoted. Since the path is inside a string, the path needs to be double quoted. If I would have initially tested it on the command line, I would have noticed that.

user1164199
  • 359
  • 4
  • 12
  • 1
    Yes, you don’t escape your double quotes properly. VBScript uses double quotes to begin and end a string variable, this means to use double quotes in the string you need to double them. For every literal double quote in the string, double it. Should be `strCommand = """C:\Program Files\TortoiseSVN\bin\svn.exe"" info ""C:\Users\Me\Desktop\MyRepo"" > ""C:\Users\Me\Documents\Output.txt"""`. – user692942 Dec 05 '19 at 23:36
  • I have looked many places and I have only seen the double quoting done with quotes within a string. My script was based off of https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1c20b3e8-d0b1-464a-a08e-01e2beb91918/how-to-run-the-command-using-vbscript-and-append-all-op-in-single-file?forum=ITCG. Here are some other websites that mention quotes in vbscript strings: https://support.smartbear.com/testcomplete/docs/scripting/working-with/strings/vbscript.html#Basics, https://www.tutorialspoint.com/vbscript/vbscript_strings.htm. – user1164199 Dec 05 '19 at 23:45
  • 2
    Sorry, are you asking for help or trying to teach me badly about the intricacies of strings in VBScript? To try and respond to your comment... Program paths in the command line will not work as expected if they contain spaces but are not encapsulated in double quotes regardless of whether VBScript is used. So when used in VBScript those literal double quotes that are part of the command have to be escaped by doubling them. – user692942 Dec 05 '19 at 23:50
  • Sorry, I wasn't trying to teach you. I just had some doubts, because all the places I checked didn't say or do anything like that. I tried your example and I still get an empty file. I went to the link you posted and the second answer only uses a double quote when a quote is inside a quote. Also, the poster at that link only had an issue when he wasn't double quoting a quote within a quote. – user1164199 Dec 05 '19 at 23:57
  • The path needs to have double quotes in it which means if you try to use that path as part of a VBScript as a string command those double quotes will need escaping. There is a simple test go run the command using the command prompt without including VBScript, what result does the output file give? If it’s blank the issue is the command which will need rectifying first. – user692942 Dec 06 '19 at 00:04
  • 2
    Ok, you are correct. My issue was with not also double quoting the path that contained a space. It works now. Thanks. – user1164199 Dec 06 '19 at 00:04

0 Answers0