1 Screenshot

About This File

Hello Everyone :), Are you tired of searching the forum for getting both the exit code & the stdout output? Then your are in the right place!


With this UDF you can get the both output & exit code of the command or the console app! Or you can get the exit code of another process without having to use RunWait...


1. Simple & Lightweight (15 KB)

2. Detailed comments & description

3. Flexible functions with many optional parameters :)

A BIG THANKS TO PsaltyDS for the functions! 2 of the (main) functions in the UDF are his work :)


List of functions:

_Process_RunCommand: Runs a command or a executable

_Process_WaitUntil: Waits until a process starts or quits. Also returns the exit code...

_Process_GetPID: Gets the PID of the process using the name of the process

_Process_GetPath: Get the path of a process along with its arguments (if any)

_Process_GetHandle: Gets the handle of a process, will be used later to retrive the exit code

_Process_CloseHandle: Closes the Process Handle of a process

_Process_GetExitCode: Gets the exit code of a process

_Process_DebugRunCommand: Debugs a command in CMD style, see the example.

What's New in Version 1.3


Added $PROCESS_DEBUG option

Changed Constant's values, they now are powers of 2 (for compatability with BitAND)

Changed _Process_RunCommand to accept $PROCESS_DEBUG, You can now debug directly using this function :)

Changed _Process_DebugRunCommand, Now you can resize it


Also some little cleanups ;)

2 people like this

User Feedback

You may only provide a review once you have downloaded the file.


  • 5
   1 of 1 member found this review helpful 1 / 1 member

Nice UDF

Share this review

Link to review

· Edited by TheDcoder

  • 5

5 Stars, Please submit your reviews too :)


P.S Feel free to vote 3 stars :lol:

Share this review

Link to review
  • Similar Content

    • fopetesl
      By fopetesl
      I have problems running both Bat files and Command line instructions.
      This function hopefully shows what I have tried so far
      Global $fFileToCreate = "", $DOS ScanFilm($fFileToCreate) Func ScanFilm($fFileToCreate) MsgBox($MB_SYSTEMMODAL, "Scanning Status", $fFileToCreate) ; $DOS = Run(@ComSpec & " /c " & "scan.bat" & @CRLF, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $DOS = Run(@ComSpec & " /k " & "ncat 80 <scant.txt >scanrep", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ; $DOS = _RunDOS("ncat 80 <scant.txt >scanrep") ProcessWaitClose($DOS) $Message = StdoutRead($DOS) MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $Message) Endfunc My first attempt running scan.bat reveals a bug in cmd.exe where the result of
      echo !SR | ncat 80 > scanrep is
      C:\S3_GUI\ncat>scan.bat C:\S3_GUI\ncat>echo scant.txt | ncat 80 1>scanrep Ncat: . C:\S3_GUI\ncat> note the added '1' which then throws the error, (when client is connected), "File or directory not found" so the command fails.  This has been run on four different computers running Windows 7 with same result.
      Next using Run() seems to truncate the command so $DOS reads:

      Using _RunDOS() doesn't throw any error but MsgBox() is empty.

    • tcox8
      By tcox8
      Currently I am running a script that calls a powershell script. To read the results of that I am reading StdOut. I am parsing things accordingly but unfortunately it doesn't parse correctly all the time and I end up missing parts of the string or other problems. My question then is, what is the best results for reading what is returned when running a powershell script or something similar?
    • Eddi96
      By Eddi96
      Hey guys!
      I need your help again. So I am working on a Project with which I can Logoff a User in a Terminal-Server (Windows Server 2012 R2), logged in as Admin. Then backup the users partition and log him back in. Sounds pretty easy for you guys, right? So my problem is... I seem to not be able to get the User ID. You can see and display the ID in a textfile with:
      Run("query user>>c:\users\example\desktop\helpmeguys.txt") This line just writes a textfile of "query user" on the desktop. This is an example on what it looks like:
      >wg                                  console                       2  Aktiv                     17    25.07.2016 08:19

      What I need right now is the ID. Any Idea on how to read it off of the Textfile?
      Please give me examples because I am still a rookie!
      With kind regards
    • FMS
      By FMS
      I've made a GUI that can send multiple commands.
      The way I'm doing this at the moment is whit "send" commands.
      also first go to the right directory where the "to be used" program sits
      And send from there the commandline argument whit parameters.
      Here is a example of the way I'm using it now:
      Func restart_app($xip) Run("C:\WINDOWS\system32\cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Sleep(50) send("cd\" & "{ENTER}") Sleep(50) send("cd Tools" & "{ENTER}") Sleep(50) send("pskill \\" & $$xip & " -u username -p pass /accepteula app.exe" & "{ENTER}") EndFunc This way is working and I got no problems whit this.
      Also I realy think there is a mush better and way to do the same and maybe a little bit less error free
      (even better if this is hidden for the user :))
      On this forum I could not find anything related to this subject (or I was not looking in the right direction) and hope somebody knows a better way
      Is there a way where u can send the arguments and parameters directly in 1 line to the commandpromt whitout using "send" to commandprompt?
      Thanks in advanced

      ps: I also tried :
      ShellExecute("pskill", "\\" & $xip & " -u username -p pass /accepteula app.exe")

      But din't work
    • milky
      By milky
      I wrote a small AutoIt App which takes DOS formatted textfiles and forwards them to MS Word. I searched a lot for a programm which does this, but I didn't find one.
      The reason for it is an old DOS program, which is used a lot, even today. The user wanted to print the output of that programm with some other font-size, font-style and so on... We used WinPrint, but this is a printing only app, so no formatting can be done afterwards...
      The solution was, to print with the DOS prgramm to an file, e.g. C:\12345\output.txt ... then read this file, convert it to unicode, put this into word with some pre-defined font / page size and so on ... and then the user can re-format or print it now.
      Here is the main function of the Dos2Word programm I wrote:
      Func Convert2Word() ; keine datei da... If Not FileExists($sFilePath) Then Return ; noch in Beaarbeitung... If _WinAPI_FileInUse($sFilePath) Then Return ; nun aber... Local $sFilePathTemp = $sFilePath & "_" & _WinAPI_CreateGUID() & ".txt" FileMove($sFilePath, $sFilePathTemp, $FC_OVERWRITE) ; open word and create new document Local $oWord = _Word_Create() If @error Then ErrorExit("Fehler bei _Word_Create()") Local $oDoc = _Word_DocAdd($oWord) If @error Then ErrorExit("Fehler bei _Word_DocAdd()") ; seite definieren With $oDoc.PageSetup .PageHeight = $sPageHeight .PageWidth = $sPageWidth .TopMargin = $sTopMargin .BottomMargin = $sBottomMargin .LeftMargin = $sLeftMargin .RightMargin = $sRightMargin EndWith ; schrift und absatz With $oDoc.Range .Font.Name = $sFontName .Font.Size = $sFontSize EndWith With $oDoc.Range.ParagraphFormat .SpaceBefore = 0 .SpaceAfter = 0 .LineUnitBefore = 0 .LineUnitAfter = 0 .LineSpacingRule = 0 EndWith Local $hFile = FileOpen($sFilePathTemp, BitOR($FO_READ, $FO_BINARY)) Local $iError Local $iLine = 1 Do Local $sLine = FileReadLine($hFile, $iLine) $iError = @error $iLine += 1 ; ignore special escape line of cm.exe If StringLeft($sLine, 2) = Chr(27) & Chr(64) Then $sLine = StringTrimLeft($sLine, 2) $oDoc.Range.insertAfter(_WinAPI_MultiByteToWideChar($sLine, $sCodePage, 0, True) & @CRLF) Until $iError <> 0 ; und am ende löschen, sofern gewünscht FileClose($hFile) If $sFilesDelete <> "0" Then FileDelete($sFilePathTemp) EndFunc ;==>Convert2Word The Homepage of the program is here: https://mcmilk.de/projects/Dos2Word/

      The full source code and precompild signed binaries for 32bit and 64bit systems are also there, the License is GPLv2
      With best regards, Milky
      Maybe someone finds it useful too