Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 如何使用WShell.run运行多个dos命令_Vbscript_Cmd - Fatal编程技术网

Vbscript 如何使用WShell.run运行多个dos命令

Vbscript 如何使用WShell.run运行多个dos命令,vbscript,cmd,Vbscript,Cmd,我的用例是在vbscript中模拟dos命令 cmd CD C:/ cmd Dir cmd echo Error Code=%ErrorLevel% >> c:\error.txt 我可以写vbscript代码直到cmd Dir,但不知道如何在单个vbscript代码中模拟错误代码 Dim oShell Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run "cmd /K CD C:\ & Dir" S

我的用例是在vbscript中模拟dos命令

cmd CD C:/
cmd Dir
cmd echo Error Code=%ErrorLevel% >> c:\error.txt
我可以写vbscript代码直到cmd Dir,但不知道如何在单个vbscript代码中模拟错误代码

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing

将命令放入批处理文件中,然后运行该文件

YourBatch.cmd

CD C:/
Dir
echo Error Code=%ErrorLevel% >> c:\error.txt
然后,在VBscript中调用批处理文件

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "YourBatch.cmd"
Set oShell = Nothing

您好,aphoria,我不能在vbscript中执行此操作吗?您的另一个选项是执行您所做的操作,并使用
&
&
链接命令。