从Visual Studio Debugger中调用VBScript代码的问题与从命令行调用相同脚本的问题相比 [英] Problem calling VBScript code from within Visual Studio Debugger compares to calling same script from Command line

查看:100
本文介绍了从Visual Studio Debugger中调用VBScript代码的问题与从命令行调用相同脚本的问题相比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用调试"从Visual Studio中调用vbscript时出现问题->启动操作工具,选择启动外部程序,然后从那里调用cscript.exe并传递命令行参数

PROCESSXMLMESSAGEFILE.VBS IN \ INXML \ InwardsOrder TQ MCCAIN

在直接命令行中调用相同的vbscript并传递相同的命令行参数会产生不同的结果

这是vbscript代码-存储在PROCESSXMLMESSAGEFILE.vbs中

设置argList = WScript.Arguments

custref = UCASE(arglist.Item(2))

'custref ='MCCAIN'

暗淡FileListSource

昏暗的oFileSource

设置oFSO = CreateObject("Scripting.FileSystemObject")

设置oFileSource = oFSO.GetFile("c:\ TESTONLY \ TQMCCAIN.xml")

MsgBox"oFileSource.Name" & oFileSource.Name& "custref" &客户咨询"Instr(1,oFileSource.Name,custref)" & Instr(1,oFileSource.Name,custref)

当我将custref更改为硬代码文本"MCCAIN"时,或当我更改"MCCAIN"的位置时因此在命令行列表中将其设置为1(PROCESSXMLMESSAGEFILE.VBS IN \ INXML \ InwardsOrder MCCAIN TQ MCCAIN)在两种情况下均有效,但是当我从arglist.Item(2)中选取它时 因此,(PROCESSXMLMESSAGEFILE.VBS IN \ INXML \ InwardsOrder TQ MCCAIN)在Visual Studio中不起作用....

事实上,这使我想知道arglist()是否没有正确地考虑将参数包括或不包括VBS名称......,我认为这是关键........ Instr几乎是一条红鲱鱼,除了我无法解释它如何正确设置 custref的值(显然在arglist.Item(2)行,但随后在Instr行中似乎已将其忘记了(但仅在Instr调用中!!?!

问题围绕在oFileSource.Name中找到字符串custref

从Visual Studio调试器内部运行相同的代码,说在oFileSource.Name中不存在MCCAIN的情况-但直接从命令行运行总是可以正确找到它

一个人解决了这个问题,谢谢任何人答复

如果我两次传递第二个参数并坚持使用arglist.Item(2),则在两种情况下都可以使用

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! 11


Steve Giergiel

解决方案

请您尝试以下操作脚本以打印出传递给脚本的参数?

 

WScript.Echo"arg count:",WScript .Arguments.Count

 

Dim i

i = 0

对于WScript.Arguments中的每个参数

下一个

 

设置argList = WScript.Arguments

custref = UCASE(arglist.Item(2))

WScript.Echo第二个参数是:" ,客户参考

 

WScript.Sleep(3000000)

 

我这边的输出是(带有或不带有VS Debugger的):

 

arg计数: arg 0-> IN \ INXML \ InwardsOrder

arg 1-> TQ

arg 2-> MCCAIN

第二个参数是:MCCAIN


Problem is seen when I call a vbscript from within Visual Studio Using the Debug - > Start Action facility and selecting the Start external Program and calling cscript.exe from there and passing in command line arguments

PROCESSXMLMESSAGEFILE.VBS IN\INXML\InwardsOrder TQ MCCAIN

calling the same vbscript from a direct command line passing in same command line arguments gives different results

Here's the vbscript code - stored within PROCESSXMLMESSAGEFILE.vbs

Set argList = WScript.Arguments

custref = UCASE(arglist.Item(2))

'custref = "MCCAIN"

Dim FileListSource

Dim oFileSource

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFileSource = oFSO.GetFile("c:\TESTONLY\TQMCCAIN.xml")

MsgBox "oFileSource.Name" & oFileSource.Name & "custref" & custref & "Instr(1,oFileSource.Name , custref)" & Instr(1,oFileSource.Name , custref)

when I change custref to hard code text "MCCAIN" or when I change the position of "MCCAIN" in the command line list to 1 thus(PROCESSXMLMESSAGEFILE.VBS IN\INXML\InwardsOrder MCCAIN TQ MCCAIN)  it works in both cases, but when I pick it up from arglist.Item(2) thus(PROCESSXMLMESSAGEFILE.VBS IN\INXML\InwardsOrder TQ MCCAIN) it does not work in Visual Studio....

In fact that lead me to wonder if the arglist() was not properly considering the arguments as including or not including the VBS name ...... and I think that's the key ........ Instr is almost a red herring, except I cant explain how it correctly sets the value of custref (apparently at the arglist.Item(2) line but then in the Instr line it seems to have forgotten it (but only in the Instr call?!?!

Problem revolved around the finding of the string custref within oFileSource.Name

Running the same code from Inside Visual Studio Debugger, says that MCCAIN not there in the oFileSource.Name when it is - but running directly from the command line always finds it correctly

SOLVED THIS ONE BY MYSELF THANKS TO ANYONE replying

If I pass the second argument twice and stick with arglist.Item(2) it works in both scenarios

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11


Steve Giergiel

解决方案

Could you please try following script to print out arguments passed to the script?

 

WScript.Echo "arg count: ", WScript.Arguments.Count

 

Dim i

i = 0

For Each arg in WScript.Arguments

    WScript.Echo "arg", i, "-->", arg

    i = i+1

Next

 

Set argList = WScript.Arguments

 

custref = UCASE(arglist.Item(2))

WScript.Echo "the 2nd argument is:", custref

 

WScript.Sleep(3000000)

 

The output in my side is (both with or without VS Debugger):

 

arg count:  3

arg 0 --> IN\INXML\InwardsOrder

arg 1 --> TQ

arg 2 --> MCCAIN

the 2nd argument is: MCCAIN


这篇关于从Visual Studio Debugger中调用VBScript代码的问题与从命令行调用相同脚本的问题相比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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