如何使用命令行在命令提示符窗口中显示来自 VBScript 的 ECHO [英] How to display ECHO from VBScript in Command Prompt window with command line
问题描述
在批处理文件中,我有以下命令:
In batch file I have the command below:
WScript ABC.vbs
在ABC.vbs
中:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Hello"
当我运行批处理文件时,会弹出一条带有文本Hello"的消息.但我想要的是在命令提示符窗口中显示消息Hello",就像我右键单击 ABC.vbs
然后选择使用命令提示符打开"一样.
When I run the batch file there is a pop-up message with the text "Hello". But what I want is showing the message "Hello" in the Command Prompt window like I do the right click on ABC.vbs
and then select "Open with command prompt".
推荐答案
除了使用 cscript.exe ABC.vbs
作为命令行的两个注释之外,这里还有一个函数你可以放在您的 .vbs 脚本中确保它始终与 cscript 引擎一起运行,无论它如何调用.
In addition to the two comments to use cscript.exe ABC.vbs
as your command line, here is a function you can put in your .vbs script to ensure it always runs with the cscript engine, no matter how it's called.
Sub checkengine
pcengine = LCase(Mid(WScript.FullName, InstrRev(WScript.FullName,"\")+1))
' BEGIN CALLOUT A
If Not pcengine="cscript.exe" Then
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
WScript.Quit
End If
' END CALLOUT A
End Sub
来自此站点:强制 VBScript 文件以 CScript 模式运行一个>
将 Call checkengine
放在 vbscript 的开头.如果它检测到 cscript.exe 不在命令行中,它会使用该引擎重新启动脚本.
Put Call checkengine
at the beginning of your vbscript. If it detects that cscript.exe is not in the command line, it relaunches the script with that engine.
这篇关于如何使用命令行在命令提示符窗口中显示来自 VBScript 的 ECHO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!