Sign in to follow this  
Followers 0
myspacee

DOS console alert if bad parameters

4 posts in this topic

hello to all,

can't find hint about bad or missing parameters.

run exe in DOS mode that need 2 or more par,

if user not respect rules exe return usage metod

find only exit if parameters is missing.

If $CmdLine[0] = 0 Then

Exit

EndIf

i want an output error on DOS console

ex:

dir /? -> usage switches

myapplication.exe [without par] -> usage method

Share this post


Link to post
Share on other sites



If I understand you good, then you may want this example

If $CmdLine[0] < 2 Then
    ; Less then 2 parameters so show help then exit
    ConsoleWrite('dir /? -> usage switches' & @CRLF)
    Exit
ElseIf $CmdLine[0] And $CmdLine[1] = '/?' Then
    ; /? used so show help then exit
    ConsoleWrite('dir /? -> usage switches' & @CRLF)
    Exit
EndIf

:)

Share this post


Link to post
Share on other sites

I find in manual this :

_____ConsoleWrite_______________________________________________________________

Remarks

The purpose for this function is to write to a console which many popular text editors can read.

This does not write to a DOS console. < -------------------- !

_______________________________________________________________________________

I want output message to DOS console...

Share this post


Link to post
Share on other sites

@myspacee

You need the latest SciTe editor AutoItWrapper option to make a CUI Portable Executable

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; compile as CUI and run

; NOTE: requires latest version of SciTe editor or autoitwrapper with compile option 
; to change PE header subsystem to CUI instead of GUI (or get makecui.exe)
; note the compiler directive: #AutoIt3Wrapper_Change2CUI=y

; needs error handling for duplicate commandline options e.g. @ScriptName  /option1 /option1
; would meet minimum requirement of 2 params but commands are duplicates.

If Not @Compiled Then Exit

; optional commandline file info
Global $properties
Global $aFileInfo[2]
$aFileInfo[0] = "FileVersion"
$aFileInfo[1] = "Language"

If Not $CmdLine[0] Then ; empty commandline
    ConsoleWrite(@CRLF & "Missing commandline parameters" & @CRLF & _
            "Type " & @ScriptName & " /? for help" & @CRLF)
    Exit
Else
    Switch $CmdLine[1] ; single commands allowed if one of below params
        Case '/?' ; /? used so show help then exit
            ConsoleWrite(@CRLF & "Command line requires minimum of 2 parameters to run" & @CRLF & _
                    "unless using '/?' for help or 'Info' for program information" & @CRLF & _
                    "Enter parameters separated by a space and preceded by '/'" & @CRLF & _
                    "e.g. " & @ScriptName & " /option1 /option2")
            Exit
        Case '/Info'; (optional) show program details then exit
            For $i = 0 To UBound($aFileInfo, 1) - 1
                $properties &= $aFileInfo[$i] & " : " & FileGetVersion(@AutoItExe, $aFileInfo[$i]) & @CRLF
            Next
            ConsoleWrite(@CRLF & "AutoIt3 Compiled Script Info" & @CRLF & $properties)
            Exit
    EndSwitch

    If $CmdLine[0] < 2 Then ; Less then 2 parameters so show help then exit
        ConsoleWrite(@CRLF & "Minimum number of commandline parameters with exception of '/?' or 'Info' is two:" & @CRLF & _
                "Type " & @ScriptName & " /? for help" & @CRLF)
        Exit
    EndIf
    For $element In $CmdLine
        Switch $element
            Case "/option1"
                ConsoleWrite("You chose option1" & @CRLF)
            Case "/option2"
                ConsoleWrite("You chose option2" & @CRLF)
            Case "/option3"
                ConsoleWrite("You chose option3" & @CRLF)
        EndSwitch
    Next
EndIf

I see fascists...

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