Is there a limit to the length of the text you can use as a parameter? If so, what is the limit?
I have a VBScript that takes 5 arguments as parameters from the command line. Two of the 5 arguments contain the full absolute path to some .txt file, so the length of the command line parameter can take so long, and my script automation may fail in this case.
Can anyone tell me if there is a limit on the length of text to be passed on the command line for VBScript? Actually, I want to know if there is a limitation in terms of VB script?
I run the script like this:
cscript.exe Sample.vbs "C:\Program Files\z.txt" param2 param3 D:\abcd.txt param5
source to share
I found this: http://blogs.msdn.com/b/oldnewthing/archive/2003/12/10/56028.aspx
But it's best to check it out yourself. Try calling it insanely long string and then in your vb script output the string or output the length of the string. I don't think you will have a file path length problem.
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 exceeded 6540 * 5 characters = 32700. You can play with it more if you like. If I put 6541 I got:
Windows script Host
Script: C: \ temp \ vbscripttest \ a.vbs Line: 9 Char: 1 Error: filename or extension is too long. Code: 800700CE Source: (null)
OK
source to share