| View previous topic :: View next topic |
| Author |
Message |
Beowolf
Joined: 22 Sep 2005 Posts: 6
|
Posted: Wed Nov 30, 2005 2:29 am Post subject: Limit to number of command line parameters? |
|
|
Is there a limit to the number of parameters you can pass to a script via the command line?
I currently have a program that calls a script, passing it several parameters. The script then iterates over the parameters, and does its thing.
This work fine when I only have a few parameters, say up to 20, but when I have 104 parameters the script just refuses to start.
Each parameter looks something like the following:
| Code: |
"Burngrange Store1 38672 38672,BurngrangeStore138672.2604166667-38672.3020833333" |
Is it just the case that 104 of these is too much for ahk to handle? (~7500 chars)
If so, is the best option to write these to a file, and then have ahk read the file? |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Nov 30, 2005 8:38 am Post subject: |
|
|
MyMainScript.exe /C:\MyDataFile.txt
MyDataFile.txt
| Quote: | "Burngrange Store1 38672 38672,BurngrangeStore138672.2604166667-38672.3020833333"
"Burngrange Store1 38672 38672,BurngrangeStore138672.2604166667-38672.3020833332"
"Burngrange Store1 38672 38672,BurngrangeStore138672.2604166667-38672.3020833331" |
MyMainScript.exe
| Code: | If 0 <> 1
{
MsgBox, Wrong number of parameters!
Exit
}
StringLeft, 1stChar, 1
If 1stChar = /
StringTrimLeft, 1, 1, 1
IfNotExist, %1%
{
MsgBox, Missing file or wrong path!
Exit
}
Loop, Read, %1%
{
MsgBox % A_LoopReadLine
} |
As you've said already, parameters could be limited by its number (9) and/or its number of characters. BTBH I haven't checked it (it's to early in the morning ).
What about to push/split the data into those 9 params (each data within that line separated by a separator (which gets removed by the target script using StringSplit)
| Quote: | | ...38672.3020833333"|"Burngrange Store1...|... |
|
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Nov 30, 2005 8:52 am Post subject: |
|
|
| Quote: | | Script Parameters can be any strings you want to pass into the script (but any string that contains spaces must be enclosed in double quotes). The script sees incoming parameters as the variables %1%, %2%, and so on. In addition, %0% contains the number of parameters passed (0 if none). | I might be wrong with the number of allowed params which I thought is 9. If that's the case, the limit seems to be the num of chars within a param.
Good luck.  |
|
| Back to top |
|
 |
Beowolf
Joined: 22 Sep 2005 Posts: 6
|
Posted: Wed Nov 30, 2005 11:05 am Post subject: |
|
|
I'm pretty sure that it's worked with more than 9 parameters. It could be that one of this bunch is longer than normal, and as you say, is exceeding a (theoretical) limit on the param length.
Putting it in a file is obviously the way to go, so thanks for the pointer to A_LoopReadLine! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Wed Nov 30, 2005 1:03 pm Post subject: |
|
|
I guess there is a limit on the number of chars on the command line. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Nov 30, 2005 1:11 pm Post subject: |
|
|
toralf is damn right (as often) ... | Quote: | On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.
This limitation applies to the command line, individual environment variables (such as the PATH variable) that are inherited by other processes, and all environment variable expansions. If you use Command Prompt to run batch files, this limitation also applies to batch ...
[Command prompt (Cmd. exe) command-line string limitation] |
|
|
| Back to top |
|
 |
Beowolf
Joined: 22 Sep 2005 Posts: 6
|
Posted: Wed Nov 30, 2005 1:46 pm Post subject: |
|
|
Handy to know, but I don't think this is the problem I came across.
The string of parameters was just over 7400 characters, and the total length of the string, including the call to the script is only another 40 or so chars.
Still less than 8191 characters. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Nov 30, 2005 2:23 pm Post subject: |
|
|
Since I can't think of anything in the program that limits it in any way, it seems it's an OS limitation (though apparently the 8191 figure mentioned above isn't exact).
If you want to send longer strings to a script, you might consider using a temporary file (as you suggested) or WM_COPYDATA, as described on the OnMessage page. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Nov 30, 2005 7:02 pm Post subject: |
|
|
Whoope, that's blasphemeous! The above link points to the Microsoft page If "the wizard of OS" tells you that its 8191 y'shall not doubt it!
If you dig it, youl'll get something like this ... which might be of interest too ...
| Quote: | SetEnvironmentVariable
The SetEnvironmentVariable function sets the contents of the specified environment variable for the current process.
BOOL SetEnvironmentVariable(
LPCTSTR lpName,
LPCTSTR lpValue
);
Parameters
lpName
[in] Pointer to a null-terminated string that specifies the name of the environment variable. The operating system creates the environment variable if it does not exist and lpValue is not NULL.
lpValue
[in] Pointer to a null-terminated string that specifies the contents of the environment variable. An environment variable has a maximum size limit of 32,767 characters, including the trailing null terminator.
If this parameter is NULL, the variable is deleted from the current process's environment. |
|
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Mon Jun 16, 2008 7:28 pm Post subject: |
|
|
| Is there a workaround for this that allows for many files (with long paths) to be dragged and dropped onto a compiled script? |
|
| Back to top |
|
 |
|