在VBScript中获取命令行输出(无需写入文件) [英] Getting command line output in VBScript (without writing to files)
问题描述
我正在使用VBScript,我的目标是能够用驱动器号代替我选择的路径.我需要D驱动器,如果它不可用,我需要检查它是否已经映射到正确的位置.然后,如果不是,则通知用户.我发现了这一点: http://technet.microsoft.com/en-us/library/ee156605.aspx ,我正在尝试改编他们的第二个示例:
I'm using VBScript, and my goal is to be able to substitute a drive letter for a path of my choosing. I need the D drive, and if it's not available I need to check if it's already mapped to the right spot; then notify the user if it's not. I found this: http://technet.microsoft.com/en-us/library/ee156605.aspx and I'm trying to adapt their second example:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 157.59.0.1")
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Exit Do
End If
Loop
(我的改编):
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c substr")
strText = ""
Do While Not objExecObject.StdOut.AtEndOfStream
strText = strText & objExecObject.StdOut.ReadLine()
Loop
Wscript.Echo strText
然后,我可能会搜索一个字符串,该字符串指示D驱动器的映射位置.我也尝试过objShell.Exec("subst")
,但仍然没有任何输出.有人对我可能做错的事情有任何想法吗?还是有更好的方法来讲述驱动器映射?谢谢,
Then I'll probably search for the string that tells where the D drive is mapped. I've also tried objShell.Exec("subst")
, but I still don't get any output. Does anyone have any ideas on what I might be doing wrong? Or is there a better way to tell about drive mappings? Thanks,
213897
推荐答案
您的脚本不起作用,因为您键入了错误的命令名称-它是subst
,而不是substr
.
Your script doesn't work because you've mistyped the command name - it's subst
, not substr
.
这篇关于在VBScript中获取命令行输出(无需写入文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!