所以命令(删除了您刚才所说的 THISSTRING 只是为了触发错误) WshShell.Run"cmd/k""C:\ Program Files(x86)\ Folder \ File.bat">""C:\ Program Files(x86)\ Folder \ File.txt"",1,正确 成为 WshShell.Run"cmd/k"""C:\ Program Files(x86)\ Folder \ File.bat">""C:\ Program Files(x86)\ Folder \ File.txt"",1,真 运行为 cmd/k" C:\ Program Files(x86)\ Folder \ File.bat>" C:\ Program Files(x86)\ Folder \File.txt" I get an error when I run this command and I am unsure why.Running VBScript to execute a bat file, I want to output any error messages to a log file. So to do this I have the code:Set WshShell = CreateObject("WScript.Shell")WshShell.Run "cmd /k ""C:\ProgramTHISSTRING Files (x86)\Folder\File.bat"" > ""C:\Program Files(x86)\Folder\File.txt""", 1, True(I do have the code to do this more elegantly but for the purpose of the problem, I think this reads better and quicker)Also I have put in THISSTRING on purpose for the error below.Once this executes I get this error in CMDI understand it's a space in the file name that has caused the error, however, I have the right quotes according tothis stackoverflow question so why is this error happening? 解决方案 I think the issue here is because the cmd /k needs the commands passed to it to be encapsulated in double quotes.So the command (removed THISSTRING as you said that was just to trigger the error)WshShell.Run "cmd /k ""C:\Program Files (x86)\Folder\File.bat"" > ""C:\Program Files(x86)\Folder\File.txt""", 1, TrueBecomesWshShell.Run "cmd /k """"C:\Program Files (x86)\Folder\File.bat"" > ""C:\Program Files(x86)\Folder\File.txt""""", 1, Trueand run's ascmd /k ""C:\Program Files (x86)\Folder\File.bat" > "C:\Program Files(x86)\Folder\File.txt"" 这篇关于VBScript中的文件名字符串空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-25 13:10