I've written several file processing scripts that work great from within a single .exe file. I have a need to break them up so that other calling scripts can access them.
How does one script pass a parameter (or 20) to another script without using the clipboard (like how a Windows Shortcut functions)?
If it were up to using the Command Line, then so be it... I just didn't think it needed to go that far when using a "Run, program.exe" function.
Am I wrong?
Thanks,
TXShooter
How does one .ahk / .exe script pass parameters to another script?
Re: How does one .ahk / .exe script pass parameters to another script?
For example,
Calling script:
RunWait, Test.AHK "c:\test - file number 1.dat"
Callee script, Test.AHK:
tFilename := %1%
My current implementation of this isn't working. I'm getting "Error: The following variable name contains an illegal character: "c:\test - file number 1.dat" "
Variable name -> tFilename:=%1%
Calling script:
RunWait, Test.AHK "c:\test - file number 1.dat"
Callee script, Test.AHK:
tFilename := %1%
My current implementation of this isn't working. I'm getting "Error: The following variable name contains an illegal character: "c:\test - file number 1.dat" "
Variable name -> tFilename:=%1%
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: How does one .ahk / .exe script pass parameters to another script?
https://autohotkey.com/docs/commands/Run.htm
Edit: https://autohotkey.com/docs/Scripts.htm#cmd
As for the passing of parameters, I would have to look it up. Its in the documentation somewhereWorkingDir
The working directory for the launched item. Do not enclose the name in double quotes even if it contains spaces. If omitted, the script's own working directory (A_WorkingDir) will be used.
Edit: https://autohotkey.com/docs/Scripts.htm#cmd
An example I use in my code to send variables to another scriptPassing Command Line Parameters to a Script
Scripts support command line parameters. The format is:
AutoHotkey.exe [Switches] [Script Filename] [Script Parameters]
S↓
And for compiled scripts, the format is:
CompiledScript.exe [Switches] [Script Parameters]
Code: Select all
Run %A_AHKPath% "JsonTest.ahk" %Lat% %Long% 1294 100
Re: How does one .ahk / .exe script pass parameters to another script?
That worked, but still had to use quotes.MannyKSoSo wrote:An example I use in my code to send variables to another scriptCode: Select all
Run %A_AHKPath% "JsonTest.ahk" %Lat% %Long% 1294 100
Run, Test.ahk %tFilename% "c:\test - file number 1.dat"
tFilename := %0%
Will this also work when compiled? I guess I will have to compile and find out. lol
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: How does one .ahk / .exe script pass parameters to another script?
As far as I am aware compiling a script (as long as that script you are trying to run knows what to do with the command you are sending) should work the same.
Re: How does one .ahk / .exe script pass parameters to another script?
See A_Args. Use tFilename := A_Args[1].
Re: How does one .ahk / .exe script pass parameters to another script?
I tried that but all that came up was a blank. I even tried A_Args[0], A_Args[2], and A_Args[3] just to make sure. No joy.Flipeador wrote:See A_Args. Use tFilename := A_Args[1].
Re: How does one .ahk / .exe script pass parameters to another script?
Well, A_Args needs AHK v1.1.27+, but just in case there is the still working legacy method:
See https://autohotkey.com/docs/Scripts.htm#cmdLegacy: The command line parameters are also stored in the variables %1%, %2%, and so on, as in versions prior to [v1.1.27]. In addition, %0% contains the number of parameters passed (0 if none).
Re: How does one .ahk / .exe script pass parameters to another script?
In Windows 10, do I have to reboot for the update to take effect? (I wouldn't think that to be necessary.) Because I just upgraded from 1.1.26.01 to 1.1.29.1 and %0% is still working while A_Args[1] is not.gregster wrote:Well, A_Args needs AHK v1.1.27+, but just in case there is the still working legacy method:See https://autohotkey.com/docs/Scripts.htm#cmdLegacy: The command line parameters are also stored in the variables %1%, %2%, and so on, as in versions prior to [v1.1.27]. In addition, %0% contains the number of parameters passed (0 if none).
Code: Select all
ProcessCommandLine()
{
global
rFilename := %0%
aFilename := A_Args[1]
MsgBox % "tFlename is: `n" rFilename "`n`naFilename is: `n"
}
Re: How does one .ahk / .exe script pass parameters to another script?
No, rebooting is not necessary, but something seems wrong...
Shouldn't %1% the corresponding command line parameter to A_Args[1]? Afaik, %1% = A_Args[1]
%0% contains the number of parameters passed, so it should be the same like A_Args.Length()
Shouldn't %1% the corresponding command line parameter to A_Args[1]? Afaik, %1% = A_Args[1]
%0% contains the number of parameters passed, so it should be the same like A_Args.Length()
Re: How does one .ahk / .exe script pass parameters to another script?
Well, something just changed in between tests, and now things are acting like how you described them to be. I didn't even reboot either.gregster wrote:No, rebooting is not necessary, but something seems wrong...
Shouldn't %1% the corresponding command line parameter to A_Args[1]? Afaik, %1% = A_Args[1]
%0% contains the number of parameters passed, so it should be the same like A_Args.Length()
I have asked this before, if there's some kind of hidden working directory that needs to be flushed out from time to time... odd things like this keep happening with subtle minor changes. (Could just be my machine too, which would also strike me as odd.)
Re: How does one .ahk / .exe script pass parameters to another script?
I think rFilename := %0% should be rFilename = %1%.
And.. MsgBox % "rFilename is: " . rFilename . "`naFilename is: " . aFilename.
And.. MsgBox % "rFilename is: " . rFilename . "`naFilename is: " . aFilename.
Who is online
Users browsing this forum: AHK_user and 197 guests