Jump to content

CMDLINE


Tiger
 Share

Recommended Posts

Can everybody help me? OK i have a question for CMDLINE. I would like to write the things behind the parameter "/set"

OK i would like to write general, path in col 0 and test 1, C:\test in col 1

Your question is about as clear as mud to me. Where does CMDLINE have Col 0 and Col 1? Are you taking about running the command from the command interpreter?

As in using a pipe in the string

$Path = "C:\My Folder\"
Run (@ComSpec & " /c " & $Path & "Test.exe /set General=Test 1|C:\Test")
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Func getNamedArgument($NamedArgument)
    For $i = 1 to $CmdLine[0]
        If stringinstr($CmdLine[$i],$NamedArgument) Then 
            $TmpArray = StringSplit($CMDLINE[$i],':')
            Global $return = $TmpArray[2]
        EndIf
    Next
EndFunc

useage:

getnamedargument("/test")

$return contains the value after the named argument (is what it is called in vbscript)

Edited by lordofthestrings
Link to comment
Share on other sites

Your script isn't good.

I have write this script

#include <Array.au3>

If $CMDLINE[0] > 0 Then
    
    $var = GetParameters($CMDLINE[1])
    
    _ArrayDisplay($var)
    
EndIf

Func GetParameters($s_cmdline)
    
    Dim $tmp_array[1][2]
    
    $array = StringSplit($s_cmdline, ",")
    
    If UBound($array, 0) = 1 Then
        
        ReDim $tmp_array[UBound($array)][2]
        
        For $i = 1 To UBound($array) - 1
            
            $part = StringSplit($array[$i], "=")
            
            $tmp_array[$i][0] = $part[1]
            $tmp_array[$i][1] = $part[2]
            
        Next
        
        $array = $tmp_array
        
    EndIf
    
    Return $array
    
EndFunc   ;==>GetParameters
Edited by Tiger
My UDFs:- _RegEnumKey
Link to comment
Share on other sites

The 'IF' condition here is unnecessary:

$array = StringSplit($s_cmdline, ",")
   
    If UBound($array, 0) = 1 Then

    ; ...

    EndIf

Ubound($array, 0) tells you how many subscripts (dimensions) an array has.

StringSplit() always returns a 1D array, whether the delimiter is found or not, so that Ubound will always be 1 and the 'IF' will always be satisfied.

Beyond that, I don't see how an example of StringSplit with comma as a delimiter has anything to do with your example in the original post -- which has no commas in it. In that example:

$CMDLINE[0] = 2

$CMDLINE[1] = "/set"

$CMDLINE[2] = ""General=Test 1|Path=C:\Test""

Now, what did you want to do with that...?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You can change the comma

Or perhaps YOU could... :)

Look at my last post and what it means for the code you posted:

1. You have to check two parameters in that format: first check for "/set" in $CMDLINE[1], then parse the stuff in $CMDLINE[2].

2. After the StringSplits, use $array[0] to know how many parts there are, and $parts[0] should always be 2 if you have a proper a=b pair.

3. ReDim works but isn't necessary if you don't Dim the 2D $tmp_array until you have $array[0] to tell you how many rows it needs.

4. The 'IF' check for Ubound($array, 0) is unnecessary, as pointed out earlier. If you want to see if the StringSplit found the delimiter at all, check @error.

5. Watch out for array size, and whether you want a 0-based or 1-based array for $tmp_array. From your example input, there will be two a=b pairs to return. AutoIt arrays are 0-based, if you want the parts to start at [1][0] instead of [0][0], then you should declare the array like this: Dim $tmp_array[ubound($array)][2] = [[$array[0], ""]]

That will give $tmp_array the same number of rows as $array, and set [0][0] to the same count that was in $array[0]. When you get the returned array it will have the count in [0][0] = 2, the first pair will be [1][0] = "General" and [1][1] = "Test 1", the second pair will be [2][0] = "Path" and [2][1] = "C:\Test".

Try it with those fixes. You can make it work.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...