Jump to content

Recommended Posts

Posted

Hello, I seem to be having trouble with getting %errorlevel% codes from the cmd prompt. I'm trying to add some error checking to a script. Here's a snipit:

Local $logfile = "D:\scripting_tests\build_log.txt"

_RunDOSDelay('ipconfig','IPCONFIG')
_RunDOSDelay("C:\Windows\System32\inetsrv\appcmd set config /section:defaultDocdument /-files.[value='default.asp']","IIS!")

Func _RunDOSDelay($cmd, $program = "")

_RunDos($cmd)
If @error Then
MsgBox(4096, "Value", @error)
WriteLog("Unable to install a program - " & $program)
Else
MsgBox(4096, "Value", @error)
WriteLog($program & " - Completed Successfully!")
EndIf
Sleep(6000)
EndFunc ;==>_RunDOSDelay

Func WriteLog($notice)
If Not FileExists($logfile) Then
_FileCreate($logfile)
EndIf
_FileWriteLog($logfile, $notice, -1)
Return
EndFunc ;==>WriteLog

I've tried several things to do this (compiling as CUI, using RunWait in combination with RunDos) and just can't seem to get it. In the above example, I purposefully made a type to hopefully get it to return an error. I also tried running "%errorlevel% after the command on the same window; I always seem to get a return saying the command completed successfully, even though it didn't. Any help would be appreciated! I've done a lot of searching, but maybe I'm just overlooking the answer and need a nudge in the right direction. :mellow:

Posted

Hi,

Without trying to fix your code, why don't you try the Run function? You can then use the stderr function.

Br, FireFox.

Posted

Read the manual on _RunDos, it returns the exit code of the command. That's the same value as %ERRORLEVEL% gets set to.

#include <Process.au3>
Global $iErrorLevel =_RunDos('ipconfig')
MsgBox(0,'', 'exit code: ' & $iErrorLevel & @CRLF & '@error: ' & @error)
$iErrorLevel =_RunDos('ipconfi') ; Typo!
MsgBox(0,'', 'exit code: ' & $iErrorLevel & @CRLF & '@error: ' & @error)
$iErrorLevel =_RunDos('ipconfig /wtf') ; Switch doesn't exist!
MsgBox(0,'', 'exit code: ' & $iErrorLevel & @CRLF & '@error: ' & @error)

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Posted

Going back to basics, you should look at RunWait in the help too.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...