VBS如何使用带有空格的字符串变量调用cmd.exe [英] VBS How to call cmd.exe using a string variable with spaces

查看:945
本文介绍了VBS如何使用带有空格的字符串变量调用cmd.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用以下内容:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /c copy /y C:\input\" & WScript.Arguments(0) & " C:\output", 0

其中输入参数可以是File Name.txt 。我已经看到无数的人做同样的事情使用双引号为硬编码文件位置,但没有使用输入参数或变量。需要什么语法,以便命令行接收:

where the input argument may be "File Name.txt". I have seen countless examples of people doing the same thing using double quotes for a hard coded file location, but nothing using an input argument or variable. What syntax is required so that the command line receives:

copy /y "C:\input\File Name.txt" C:\output

而不是

copy /y C:\input\File Name.txt C:\output

为任意文件名?

推荐答案

嵌入所需的引号周围的文字:

Embed the needed quotes (escaped via doubling) in the surrounding literals:

WshShell.Run "cmd /c copy /y ""C:\input\" & WScript.Arguments(0) & """ C:\output", 0

背景进一步阅读

这篇关于VBS如何使用带有空格的字符串变量调用cmd.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆