LeftHandedWave Posted August 31, 2016 Posted August 31, 2016 (edited) Hello folks, I'm new to AutoIt and I love it! I've used command line scripts for years, but needed something that's a little more robust. I've been teaching myself AutoIt and have run into a snag that I hope you folks can help me with. What I'm trying to do is have the script that was just run "Termed Data Copy.exe", check to see if a newer version of the file is available, then if so, update with a second script "Updater". I'm trying to pass some variables from one script to another. Here is the TDC script: ; Declare some variables Local $js = "\\bakertilly\firmdata\Data\IT\Apps\Jody Scripts\" Local $ljs = "C:\Users\Public\Jody Scripts\" Local $AppName = "Termed Data Copy" ; Check to see if this is the latest version of this script Local $SrvCopy = FileGetVersion ($js & $AppName & "\" & $AppName & ".exe", "FileVersion") Local $LocCopy = FileGetVersion (@ScriptFullPath) If $SrvCopy <> $LocCopy Then Run ($ljs & "Updater.exe " & '"' & $AppName & '" "' & @ScriptFullPath & '"') Exit EndIf And here is the code in Updater: Local $js = "\\bakertilly\firmdata\Data\IT\Apps\Jody Scripts" FileCopy ('"' & $js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe" & '"' & ", " & '"' & $CmdLine[2] & '"', 1) This doesn't work for some reason, but if I test without using variables, it works as expected. FileCopy ("\\bakertilly\firmdata\Data\IT\Apps\Jody Scripts\Termed Data Copy\Termed Data Copy.exe", "C:\Users\jp12440\Documents\_JodyBuilt\AutoIt\Termed Data Copy.exe", 1) The goal is to use this Updater script to be used for some other scripts, so I don't want to hardcode the location of the scripts. Any ideas on what I should try? Could there be a better way of transferring the variables that I'm not seeing? I've tried many combinations of variables in the Updater script, but still isn't working. Here is the MsgBox from the CmdLineRaw. It's showing both $CmdLine[1] and $CmdLine[2] Edited August 31, 2016 by LeftHandedWave I spel gud
ViciousXUSMC Posted August 31, 2016 Posted August 31, 2016 A script can only reference itself for variables. If you need to hand them off from one script to another (and cant combine the two scripts into one) You could try something like an .ini file or saving/reading to the registry.
LeftHandedWave Posted August 31, 2016 Author Posted August 31, 2016 1 minute ago, ViciousXUSMC said: A script can only reference itself for variables. If you need to hand them off from one script to another (and cant combine the two scripts into one) You could try something like an .ini file or saving/reading to the registry. This works fine to pass the variable to a MsgBox, but FileCopy dosen't work. I would prefer using the Command Line Parameters from the help file, but for some reason, it's not working as listed. In other words, why does this work: MsgBox (0, "test", '"' & $js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe" & '"' & ", " & '"' & $CmdLine[2] & '"') But this doesn't work: FileCopy ('"' & $js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe" & '"' & ", " & '"' & $CmdLine[2] & '"', 1)
jguinch Posted August 31, 2016 Posted August 31, 2016 (edited) The method is good, but you have an error in your FileCopy line. Please, try this one : FileCopy ($js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe", $CmdLine[2], 1) Also, make sure that the @ScriptFullPath is not running while the updater starts the copy (add a Sleep(200) or more because the FileCopy line) Edit : another way to pass parameters to a script can be to use the environment variables using EnvSet + EnvGet Edited August 31, 2016 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
AutoBert Posted August 31, 2016 Posted August 31, 2016 14 minutes ago, ViciousXUSMC said: A script can only reference itself for variables. correct, but you can run a script with params as TE did. @LeftHandedWave: test the incoming values with ConsoleWrite.
LeftHandedWave Posted August 31, 2016 Author Posted August 31, 2016 6 minutes ago, jguinch said: The method is good, but you have an error in your FileCopy line. Please, try this one : FileCopy ($js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe", $CmdLine[2], 1) Also, make sure that the @ScriptFullPath is not running while the updater starts the copy (add a Sleep(200) or more because the FileCopy line) Thank you! I've been playing around with this for 5 hours. So, I don't need double quotes around a path with a space if it comes from a variable?
jguinch Posted August 31, 2016 Posted August 31, 2016 Here is the method using environment vars : Main script : ; Declare some variables Local $js = "\\bakertilly\firmdata\Data\IT\Apps\Jody Scripts\" Local $ljs = "C:\Users\Public\Jody Scripts\" Local $AppName = "Termed Data Copy" ; Check to see if this is the latest version of this script Local $SrvCopy = FileGetVersion ($js & $AppName & "\" & $AppName & ".exe", "FileVersion") Local $LocCopy = FileGetVersion (@ScriptFullPath) If $SrvCopy <> $LocCopy Then EnvSet("_UPDATER_EXE", @ScriptFullPath) EnvSet("_UPDATER_NEW", $js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe") EnvSet("_UPDATER_PID", @AutoItPID) Run ($ljs & "Updater.exe) Exit EndIf Updater : $source = EnvGet("_UPDATER_EXE") $destination = EnvGet("_UPDATER_NEW") $PID = EnvGet("_UPDATER_PID") If Not FileExists($source) Or Not FileExists($destination) Or $PID = "" Then Exit Do sleep(10) Until Not FileExists($PID) FileCopy($source, $destination, 1) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
jguinch Posted August 31, 2016 Posted August 31, 2016 No, you need quotes in an external command line, not in functions where the parameter is a file name. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
LeftHandedWave Posted August 31, 2016 Author Posted August 31, 2016 4 minutes ago, jguinch said: Here is the method using environment vars : Main script : ; Declare some variables Local $js = "\\bakertilly\firmdata\Data\IT\Apps\Jody Scripts\" Local $ljs = "C:\Users\Public\Jody Scripts\" Local $AppName = "Termed Data Copy" ; Check to see if this is the latest version of this script Local $SrvCopy = FileGetVersion ($js & $AppName & "\" & $AppName & ".exe", "FileVersion") Local $LocCopy = FileGetVersion (@ScriptFullPath) If $SrvCopy <> $LocCopy Then EnvSet("_UPDATER_EXE", @ScriptFullPath) EnvSet("_UPDATER_NEW", $js & "\" & $CmdLine[1] & "\" & $CmdLine[1] & ".exe") EnvSet("_UPDATER_PID", @AutoItPID) Run ($ljs & "Updater.exe) Exit EndIf Updater : $source = EnvGet("_UPDATER_EXE") $destination = EnvGet("_UPDATER_NEW") $PID = EnvGet("_UPDATER_PID") If Not FileExists($source) Or Not FileExists($destination) Or $PID = "" Then Exit Do sleep(10) Until Not FileExists($PID) FileCopy($source, $destination, 1) Ahh... Thanks for explaining that. I'll look into using the EnvSet command.
jguinch Posted August 31, 2016 Posted August 31, 2016 It's just a way, not a definitive solution. The command line is good, too. I often use the envget/envset way because the environment variables can store up to 32,767 characters, while the command line max limit is "only" 8 191 characters (sufficient in most cases) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now