x2desmit Posted January 5, 2015 Share Posted January 5, 2015 Hello All, If I pass the command line parameters properly, the script works fine. But if I pass nothing through the command line, the whole script breaks, when I'm trying to get it to log that nothing was passed and then exit gracefully. I've tried several examples on this forum, but even the simple one line code provided in the help file did not work on my machine. If I remove the FileWriteLine in the IF statement...nothing breaks. This is very confusing. I have run this compiled and as a au3. I get an error box for Line 46 (which does not even exist in this script), and a message... 'Error: Array variables has incorrect number of subscripts or subscript dimension range exceeded' Here is the script...Any ideas? #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> Dim $User, $Password $CmdLine[0] ; Contains the total number of items in the array. $CmdLine[1] ; The first parameter. $CmdLine[2] ; The second parameter. $User = $CmdLine[1] $password = $CmdLine[2] FileWriteLine("C:UserssmithddDesktopTesting.txt", $CmdLine[0]) FileWriteLine("C:UserssmithddDesktopTesting.txt", $User) FilewriteLine("C:UserssmithddDesktopTesting.txt", $Password) FilewriteLine("C:UserssmithddDesktopTesting.txt", $CmdLineRaw) ; Alternative: If $CmdLine[0] = 0 Then FileWriteLine("C:UserssmithddDesktoptesting.log", "You offered no command line parameters. Exiting.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", "Script has command-line arguments.") Link to comment Share on other sites More sharing options...
abberration Posted January 5, 2015 Share Posted January 5, 2015 If you have passed no arguments, then you cannot have anything more than $Cmdline[0]. I would approach it this way: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> Dim $User, $Password If $CmdLine[0] <> 0 Then FileWriteLine("C:\Users\smithdd\Desktop\testing.log", "You offered no command line parameters. Exiting.") $User = $CmdLine[1] $password = $CmdLine[2] FileWriteLine(@DesktopDir & "\Testing.txt", $CmdLine[0]) FileWriteLine(@DesktopDir & "\Testing.txt", $User) FilewriteLine(@DesktopDir & "\Testing.txt", $Password) FilewriteLine(@DesktopDir & "\Testing.txt", $CmdLineRaw) Else FileWriteLine(@DesktopDir & "\testing.log", "You offered no command line parameters. Exiting.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", "Script has command-line arguments.") Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Developers Solution Jos Posted January 5, 2015 Developers Solution Share Posted January 5, 2015 What about this version: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> Dim $User, $Password ;~ $CmdLine[0] ; Contains the total number of items in the array. ;~ $CmdLine[1] ; The first parameter. ;~ $CmdLine[2] ; The second parameter. If $CmdLine[0] > 0 then $User = $CmdLine[1] If $CmdLine[0] > 1 then $password = $CmdLine[2] FileWriteLine("C:\Users\smithdd\Desktop\Testing.txt", $CmdLine[0]) FileWriteLine("C:\Users\smithdd\Desktop\Testing.txt", $User) FilewriteLine("C:\Users\smithdd\Desktop\Testing.txt", $Password) FilewriteLine("C:\Users\smithdd\Desktop\Testing.txt", $CmdLineRaw) ; Alternative: If $CmdLine[0] = 0 Then FileWriteLine("C:\Users\smithdd\Desktop\testing.log", "You offered no command line parameters. Exiting.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", "Script has command-line arguments.") Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
x2desmit Posted January 5, 2015 Author Share Posted January 5, 2015 Hi Jos, thanks for the response. You have somehow managed to stop it from breaking....but the log file does not show an entry with feedback. I'll keep plugging away... Thank you! DS Link to comment Share on other sites More sharing options...
x2desmit Posted January 5, 2015 Author Share Posted January 5, 2015 I get the same behaviour as I get with Jos's script. The script does not break, but it will not process the 'FileWriteLine' command....Weird. Thank you both for your quick respones. If you have passed no arguments, then you cannot have anything more than $Cmdline[0]. I would approach it this way: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> Dim $User, $Password If $CmdLine[0] <> 0 Then FileWriteLine("C:\Users\smithdd\Desktop\testing.log", "You offered no command line parameters. Exiting.") $User = $CmdLine[1] $password = $CmdLine[2] FileWriteLine(@DesktopDir & "\Testing.txt", $CmdLine[0]) FileWriteLine(@DesktopDir & "\Testing.txt", $User) FilewriteLine(@DesktopDir & "\Testing.txt", $Password) FilewriteLine(@DesktopDir & "\Testing.txt", $CmdLineRaw) Else FileWriteLine(@DesktopDir & "\testing.log", "You offered no command line parameters. Exiting.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", "Script has command-line arguments.") Link to comment Share on other sites More sharing options...
Developers Jos Posted January 5, 2015 Developers Share Posted January 5, 2015 (edited) Hi Jos, thanks for the response. You have somehow managed to stop it from breaking....but the log file does not show an entry with feedback. I'll keep plugging away... Thank you! DS So the log file remain totally empty or just shows a 0 on line 1 and 3 crlf's (3 empty lines) after that? Does the file exists at all? Jos Edited January 5, 2015 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
x2desmit Posted January 5, 2015 Author Share Posted January 5, 2015 Yes, If I run the script with no log file already there, it does not create it. If it's already there, it adds nothing to it. If I pass the parameters, it will create the file and drop what I typed in that file. So the log file remain totally empty or just shows a 0 on line 1 and 3 crlf's (3 empty lines) after that? Does the file exists at all? Jos Link to comment Share on other sites More sharing options...
x2desmit Posted January 5, 2015 Author Share Posted January 5, 2015 Ok. I think I have it now. You guys are great!! I doubled up on the @DesktopDir variable and my $logfile variable. So I just used the single $logfile one and it's creating the file as expected now. Here is the script that's working as is. This will go into a bigger script of course, but you have solved my issue! THANK YOU!!!!! #include <MsgBoxConstants.au3> #include <file.au3> Dim $User, $Password, $logfile $logfile = "C:\Users\smithdd\Desktop\testing.txt" FileOpen($logfile, 2) If $CmdLine[0] <> 0 Then $User = $CmdLine[1] $password = $CmdLine[2] FileWriteLine($logfile, $User) FilewriteLine($logfile, $Password) Else FileWriteLine($logfile, "You offered no command line parameters. Exiting.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", "Script has command-line arguments.") Link to comment Share on other sites More sharing options...
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