当我使用批处理文件创建文件invisible.vbs,然后删除时,它停止并出现错误。基本上,我想做的是让批处理文件生成这个文件。
这是我在运行批处理文件时得到的错误:
C:\Users\HP\Desktop>"New Text Document.bat"
CreateObject("Wscript.Shell").Run """"
'WScript.Arguments' is not recognized as an internal or external command, operable program or batch file.
'""""' is not recognized as an internal or external command, operable program or batch file.以下是批处理文件中的内容:
@ECHO OFF
CD /D %~dp0
ECHO\ CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0,False>>Invisible.vbs
::What I want to do with the file is here
DEL %CD%\invisible.vbs /Q /S我注意到文件是生成的,但它是空的,因此当我尝试使用它使另一个批处理文件不可见时,它不会执行任何操作。
发布于 2012-12-11 05:52:11
这是由echo语句中的&符号引起的。当按字面意义使用^&时,它需要通过批处理转义字符^进行转义。您可能还希望使用单输出重定向运算符> (覆盖现有),而不是双>> (追加到现有)。
@ECHO OFF
CD /D %~dp0
ECHO.CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0,False>Invisible.vbs
::What I want to do with the file is here
DEL %CD%\invisible.vbs /Q /S另一个技巧是在创建丢弃文件时使用%TEMP%目录变量。
https://stackoverflow.com/questions/13809752
复制相似问题