可以用作参数的文本长度是否有限制?如果是,极限是多少? [英] Is there a limit in the text length that you can use as a parameter? If yes whats the limit?

查看:73
本文介绍了可以用作参数的文本长度是否有限制?如果是,极限是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VBScript,它从命令行接受5个参数作为参数。 5个参数中的2个包含指向某个.txt文件的完整绝对路径,因此命令行参数的长度可能会变得很长,并且在这种情况下我的自动化脚本可能会失败。

I have a VBScript that accepts 5 arguments as parameters from command line. Two of the 5 arguments contains complete absolute path to some .txt file, so the command line parameter length might get so long and my automation script may fail in such case.

有人可以告诉我对于在VBScript的命令行中传递的文本长度是否有任何限制?
实际上,我想知道,从VB脚本角度来看是否有限制?

Can someone tell me if we have any restriction on text length to be passed in command line for VBScript? Actually, I want to know, if there's limit from VB script point of view ?

我正在运行脚本,如下所示:

I am running the script as follows:

cscript.exe Sample.vbs "C:\Program Files\z.txt" param2 param3 D:\abcd.txt param5


推荐答案

我发现了这一点: http://blogs.msdn.com /b/oldnewthing/archive/2003/12/10/56028.aspx

但最好的办法是自己进行测试。尝试使用一个非常长的字符串来调用它,然后在vb脚本中输出该字符串,或者输出该字符串的长度。我认为您的文件路径长度不会有问题。

But your best bet is to test it out yourself. Try calling it with an insanely long string, then in your vb script output the string, or output the string's length. I don't think you are going to have a problem with file path lengths.

a.vbs

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")

Dim arguments
For i = 1 To 6540
  arguments = arguments & LPad(i,4,"0") & ","
Next

objShell.Run "b.vbs " & arguments

' Using Set is mandatory
Set objShell = Nothing


Function LPad(s, l, c)
  Dim n : n = 0
  If l > Len(s) Then n = l - Len(s)
  LPad = String(n, c) & s
End Function

b.vbs

WriteString "C:\temp\vbscripttest\c.txt",WScript.Arguments.Item(0) 

Function WriteString( filename, contents )
    Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile( filename,2,true)
    objFileToWrite.WriteLine(contents)
    objFileToWrite.Close
    Set objFileToWrite = Nothing
End Function

在6540处最大* 5个字符=32700。如果需要,可以更多地使用它。如果输入6541,则得到:

It maxed out at 6540 * 5 characters = 32700. You can play around with it more if you want. If I put 6541, I got:

脚本:C:\temp\vbscripttest\a.vbs
行:9
字符:1
错误:文件名或扩展名太长。
代码:800700CE
来源:(空)

Script: C:\temp\vbscripttest\a.vbs Line: 9 Char: 1 Error: The filename or extension is too long. Code: 800700CE Source: (null)

这篇关于可以用作参数的文本长度是否有限制?如果是,极限是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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