Prashant2329
Prashant2329

Reputation: 347

Is there a limit in the text length that you can use as a parameter? If yes whats the limit?

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.

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

Upvotes: 3

Views: 6684

Answers (1)

Derek
Derek

Reputation: 8773

I found this: http://blogs.msdn.com/b/oldnewthing/archive/2003/12/10/56028.aspx

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

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


Windows Script Host

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


OK

Upvotes: 2

Related Questions