Sign in to follow this  
Followers 0
AutoitNew94

Help Correcting Script

5 posts in this topic

I need some help cleaning up and correcting this.

$var = 0
If $Cmdline[0] > 0 Then
    For $i = 1 To $Cmdline[0]
        If $i = 1 Then $var = 1
    Next
Endif

If $Cmdline[$var] = ".." Then
    For $i = 2 To $Cmdline[0]
        ConsoleWrite($Cmdline[$i] & @LF)
    Next
EndIf

If $var = 1 Then
    For $i = 1 To $Cmdline[0]
        ConsoleWrite($Cmdline[$i] & " ")
    Next
EndIf

When args passed from the command line.

I want

SCRIPT.EXE Hello World ..

to result in

Hello World ..

and

SCRIPT.EXE .. Hello World

to result in

Hello

World

Thank You in advance.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites



This doesn't resemble your code at the top but it does give the result you asked for.

If $CMDLINE[0] > 0 then

    If $CMDLINE[1] = ".." then
        For $i = 2 to $CMDLINE[0]
            ConsoleWrite($CMDLINE[$i] & @crlf)
        Next
    ElseIf $CMDLINE[$CMDLINE[0]] = ".." then
        ConsoleWrite($CMDLINERAW & @crlf)
    EndIf

EndIf

Share this post


Link to post
Share on other sites

In favor of a syntax like:

SCRIPT.EXE Hello World ..
SCRIPT.EXE .. Hello World

You would do well to standardize this to:

SCRIPT.EXE Hello World
SCRIPT.EXE "Hello World"

The example below will automatically maintain "Hello World" as a single string, and split Hello World without quotes into two strings.

Share this post


Link to post
Share on other sites

You would do well to standardize this to:

SCRIPT.EXE Hello World
SCRIPT.EXE "Hello World"

Thank you Manadar you are absolutely correct.

It is much easier just to use quoted and unquoted strings.

If $Cmdline[0] > 0 Then
    For $i = 1 To $CmdLine[0]
        ConsoleWrite($CmdLine[$i] & @LF)
    Next
EndIf

My next question is could you or someone else point me in the direction of processing

chars, so when reading through a string like...

"Hello %World%"

...the script knows that %World% is a variable and to change that as needed.

More preferably the syntax would resemble $World instead of %World.%

Thank you again.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

There may be a better way but this seems to work

#include <array.au3>
If $CMDLINE[0] > 0 then
    Local $aCMDLine[$CMDLINE[0] +1]
    For $i = 1 to $CMDLINE[0]
        Switch 1
            Case StringinStr($CMDLINE[$i],"%World%"), StringinStr($CMDLINE[$i],"%Hello%")
                $aCMDLine[$i] = $CMDLINE[$i]
                $aCMDLINE[$i] = StringReplace($aCMDLINE[$i],"%World%","Earth")
                $aCMDLINE[$i] = StringReplace($aCMDLINE[$i],"%Hello%","Evening")
            Case Else
                $aCMDLine[$i] = $CMDLINE[$i]
        EndSwitch

    Next

    _ArrayDisplay($aCMDLine,"Modified Commandlines")
EndIf

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