Sign in to follow this  
Followers 0
x2desmit

$CmdLine broken?

8 posts in this topic

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.")

Share this post


Link to post
Share on other sites



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.")

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.")

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.")

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0