Jump to content
Sign in to follow this  
klaus.s

cmdlog

Recommended Posts

klaus.s

The function cmdlog allows to write to a command window (or DOS console) without the need to compile the script.

To use this function within a script, the file cmdlog_con.exe must be in the same folder. This file is created by cmdlog_con_compile.bat from cmdlog_con.au3.

cmdlog_example.au3 is a small example how to use and how it works.

All 5 files are packed in cmdlog.zip.

Maybe this is useful for some small projects. Yet I have not tested it very thoroughly (only Windows XP SP2), suggestions to make it better or faster are very welcome.

-- Klaus

cmdlog.zip

Edited by klaus.s

Share this post


Link to post
Share on other sites
Mat

I know I really should get round to finishing it at some point, but I'm also about to go on summer hols for 6 weeks so it's not going to happen any time soon, but: http://code.google.com/p/consoleau3/

Share this post


Link to post
Share on other sites
IRON

For scripts where you do not necessarily have to see the console window, you can also use the following script.

I use the code snippet to remotely control another PC via console.

(translated by google)

#include <Constants.au3>

;current working directory
consoleWriteLn( "WorkingDir = " & @WorkingDir )

;Exmaples...
cmd( "cd\Windows" )
cmd( "cd Boot" )
cmd( "d:" )
cmd( "dir" )

;current working directory
consoleWriteLn( "WorkingDir = " & @WorkingDir )

Func cmd( $prompt )
    ;check for "cd\" to change WorkingDir
    If StringInStr( $prompt, "cd\", 1 ) Then
        $prompt = StringTrimLeft( $prompt, 2 )
        Local $newDir = StringLeft( @WorkingDir, 2 ) & $prompt
        consoleWriteLn( $newDir )
        If FileChangeDir( $newDir ) Then
            consoleWriteLn( "new_WorkingDir = " & @WorkingDir )
            Return 1
        Else
            ConsoleWrite( "Fehler" & @CRLF )
        EndIf
    ;check for "cd " to change WorkingDir
    ElseIf StringInStr( $prompt, "cd ", 1 ) Then
        $prompt = StringTrimLeft( $prompt, 3 )
        Local $newDir = @WorkingDir & "\" & $prompt
        consoleWriteLn( $newDir )
        If FileChangeDir( $newDir ) Then
            consoleWriteLn( "new_WorkingDir = " & @WorkingDir )
            Return 1
        Else
            ConsoleWrite( "Fehler" & @CRLF )
        EndIf
    ;check for "?:" to change Drive
    ElseIf StringRegExp( $prompt, "\A[[:alpha:]]:", 0 ) Then
        consoleWriteLn( "Patern funst :) " & @WorkingDir )
        $prompt = StringLeft( $prompt, 2 )
        If FileChangeDir( $prompt ) Then
            consoleWriteLn( "new_WorkingDir = " & @WorkingDir )
            Return 1
        EndIf
    Else

        Local $foo = Run(@ComSpec & " /c " & $prompt, @WorkingDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        Local $line
        While 1
            $line &= StdoutRead($foo)
            If @error Then ExitLoop
        Wend

        While 1
            $line &= StderrRead($foo)
            If @error Then ExitLoop
        WEnd
        consoleWriteLn( $line )
    EndIf
    Return 0
EndFunc

Func consoleWriteLn( $d )
    ConsoleWrite( $d & @CRLF )
    Return $d
EndFunc

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  

×