Jump to content

cmdlog


klaus.s
 Share

Recommended Posts

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

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
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...