Jump to content

$CmdLine not working as espected. See details.


Recommended Posts

I have a very strange problem, maybe related to some other i have.

$CmdLine is not working as espected. 
I know, $CmdLine[0] is a counter, then [1] is the 1st param passed, and $CmdLine[0] will be 2.

Create a new au3 file and call it program as example.

Put that: 
 

#include <IE.au3> 
#include <msgboxConstants.au3>

; Definitions

If $cmdLine[0] >= 2 Then
    msgbox(4096, "param1", $CmdLine[1])
EndIf

If $cmdLine[0] >= 3 Then
    msgbox(4096, "param2", $CmdLine[2])
EndIf

If $cmdLine[0] >= 4 Then
    msgbox(4096, "param3", $CmdLine[3]) ; THIS line is not working...
EndIf

msgbox(4096, "BAD", $CmdLine[3] & @CRLF & @CRLF & "I am the 3rd param on $cmdLine[3]")
msgbox(4096, "RAW", "Full content of $CmdLineRaw:" & @CRLF & @CRLF & $CmdLineRaw)

Compile to exe, then run from command line or bat: 

start program "1" "2" "3"

The expected result is 3 message boxes with 1, 2 and finally 3. The Third never comes, but the value is in, as you can see on BAD messagebox and RAW too.

I think the $CmdLine is a basic feature... too basic to fail at this stage.
Can anyone test to know if is a fail of me?

Oh! attached files. Just unzip, see, compile and tryout. A compiled copy is attached too.

Thank you.

program.zip

~ SELF SIGNED ~

How much warning points do i need to get my free spicy hammon?

Link to comment
Share on other sites

Sure...

Add then see: 

msgbox(4096, "RAW", "Counter of $CmdLine[0]:" & @CRLF & @CRLF & $CmdLine[0])

Result = 3, with is correct.

Also add:

#include <array.au3>

 and at bottom : 

_arrayDisplay($CmdLine);

Shoud display 4 element array, wich is the desired result with the correct values.

~ SELF SIGNED ~

How much warning points do i need to get my free spicy hammon?

Link to comment
Share on other sites

  • Developers

Sure...

Add then see: 

msgbox(4096, "RAW", "Counter of $CmdLine[0]:" & @CRLF & @CRLF & $CmdLine[0])

Result = 3, with is correct.

Also add:

#include <array.au3>

 and at bottom : 

_arrayDisplay($CmdLine);

Shoud display 4 element array, wich is the desired result with the correct values.

So that means that your tests are wrong and should be:

; Definitions

If $cmdLine[0] >= 1 Then
    msgbox(4096, "param1", $CmdLine[1])
EndIf
; etc....

... right?

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

Did u see the source i uploaded? I put the raw to test it's contents.

$CmdLine is empty except if you put content in there, so the first value of $CmdLine[0] is 2, never 1.
If a command line is passed, $CmdLine[0] will be 2, and $CmdLine[1] the first value. The >= is here to test. Using only = should work.

See the example i put, see how it works OK with cmdline1 and 2, then see how is not working.
The logic is not wrong i guess.

Test it please.

 

~ SELF SIGNED ~

How much warning points do i need to get my free spicy hammon?

Link to comment
Share on other sites

Did you even read the posts? We both pointed out what was wrong with your code and gave examples as how to fix it. Test the code below..

#include <IE.au3>
#include <msgboxConstants.au3>

; Definitions


If $cmdLine[0] >= 1 Then
    msgbox(4096, "param1", $CmdLine[1])
    ;Local $url = $CmdLine[1]
EndIf

If $cmdLine[0] >= 2 Then
    msgbox(4096, "param2", $CmdLine[2])
    ;Local $mode = $CmdLine[2]
EndIf

If $cmdLine[0] >= 3 Then
    msgbox(4096, "param3", $CmdLine[3])
    ;Local $output = $CmdLine[3]
EndIf

msgbox(4096, "BAD", $CmdLine[3] & @CRLF & @CRLF & "I am the 3rd param on $cmdLine[3]")
msgbox(4096, "RAW", "Full content of $CmdLineRaw:" & @CRLF & @CRLF & $CmdLineRaw)
Edited by Geir1983
Link to comment
Share on other sites

Don't confuse $cmdLine and $cmdLineRaw. The latter has more parameters.

As the others have said, your mistake is starting at >= 2 instead of >= 1 and expecting a total count of 4 when it is only 3.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

$CmdLine is not working as espected. 

I know, $CmdLine[0] is a counter, then [1] is the 1st param passed, and $CmdLine[0] will be 2.

 

Just do an _arraydisplay() on that. The array looks like:

[0] = 1 ; where you said it is 2, which is false

[1] = "the 1st param passed"

Link to comment
Share on other sites

The expected result is 3 message boxes with 1, 2 and finally 3. The Third never comes, but the value is in, as you can see on BAD messagebox and RAW too.

 

 

You should try if it's really "1" and "2" that's given out by msgboxes, with your code it should be "2" and "3".

 

Also, you should could use this for better reading and scalability:

 

; Definitions

#cs################################################################
If $cmdLine[0] >= 2 Then
    msgbox(4096, "param1", 
$CmdLine[1])EndIf
 

If $cmdLine[0] >= 3 Then
    msgbox(4096, "param2", 
$CmdLine[2])EndIf
 

If $cmdLine[0] >= 4 Then
    msgbox(4096, "param3", $CmdLine[3]) ; THIS line is not working...
EndIf
#ce###############################################################

If isarray($CmdLine) Then
    For $i = 1 To $CmdLine[0]
        msgbox(4096, "param" & $i, $CmdLine[$i])
    Next
Else
    msgbox(4096, "No parameters were given")
Endif









Edited by Brobbl
Link to comment
Share on other sites

  • Developers

See the example i put, see how it works OK with cmdline1 and 2, then see how is not working.

The logic is not wrong i guess.

Test it please.

 

No need to test on my side and I am fine you questioning what I stated.

Good luck. ;)

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

 

Did you even read the posts? We both pointed out what was wrong with your code and gave examples as how to fix it. Test the code below..

#include <IE.au3>
#include <msgboxConstants.au3>

; Definitions


If $cmdLine[0] >= 1 Then
    msgbox(4096, "param1", $CmdLine[1])
    ;Local $url = $CmdLine[1]
EndIf

If $cmdLine[0] >= 2 Then
    msgbox(4096, "param2", $CmdLine[2])
    ;Local $mode = $CmdLine[2]
EndIf

If $cmdLine[0] >= 3 Then
    msgbox(4096, "param3", $CmdLine[3])
    ;Local $output = $CmdLine[3]
EndIf

msgbox(4096, "BAD", $CmdLine[3] & @CRLF & @CRLF & "I am the 3rd param on $cmdLine[3]")
msgbox(4096, "RAW", "Full content of $CmdLineRaw:" & @CRLF & @CRLF & $CmdLineRaw)

Oh my godness... I am totally wrong.

I don't know on what moment i've see $CmdLine[0] value as 2 using 1 param.

Thank you for your patience and sorry for inconveniences.

~ SELF SIGNED ~

How much warning points do i need to get my free spicy hammon?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...