Sign in to follow this  
Followers 0
lcloki

Problems with my Func RunDos($cmd)

3 posts in this topic

Hello everybody,

I wrote a function which executes a Dos command and returns the content of the window. So, you can run "net localgroup" to find out which groups are on your computer.

But there are some problems:

My first version runs well unter Windows XP, but doesn't run unter Windows 2000.

So I made a Version which should run unter both, but now Windows XP fails.

Does somebody know what's going on there?

Func RunDos($cmd)
        
        Dim $text
        Dim $res    = Run(@ComSpec & " /c " & $cmd, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    
        If @OSVersion = "WIN_2000" OR @OSVersion = "WIN_NT4" Then
            
            While ProcessExists($res)
                Local $nPeek = StdoutRead($res, 0, 1)
                If $nPeek Then $text = $text & @CRLF & StdoutRead($res)
                Sleep(25)
            WEnd    
        
        ElseIf @OSVersion = "WIN_XP" Then
        
            While 1
                $line = StdoutRead($res, 0, 1)
                $text = $text & @CRLF & $line
                If @error = -1 Then ExitLoop
                    MsgBox(0, "", $text)
            Wend
            
            While 1
                $line = StderrRead($res, 0, 1)
                $text = $text & @CRLF & $line
                If @error = -1 Then ExitLoop
                    MsgBox(0, "", $text)
            Wend
        
        EndIf
        
        Return $text
        
    EndFunc

Share this post


Link to post
Share on other sites



and the error is???

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try to test for the @Error right after the Std??Read command:

While 1
                $line = StdoutRead($res, 0, 1)
                If @error = -1 Then ExitLoop
                $text = $text & @CRLF & $line
                    MsgBox(0, "", $text)
            Wend
            
            While 1
                $line = StderrRead($res, 0, 1)
                If @error = -1 Then ExitLoop
                  $text = $text & @CRLF & $line
                    MsgBox(0, "", $text)
          Wend
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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