Jump to content

Problems with my Func RunDos($cmd)


Recommended Posts

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
Link to comment
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 *

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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