Jump to content

Capture output of a .BAT file inside AutoIt...


Recommended Posts


I am back with Autoit after 15 years... I have forgotten many basics it seems, but this one I am ashamed of asking!  I can't figure it out...


I am running a BAT file from within AutoIt.  The BAT file with output some simple text when I run it in the windows shell console, for example:

C:\Program Files\tos428cl>tos428cl.bat getport

The resulting text is "COM6".

How can I use @ComSpec to obtain the resulting text (COM6) and capture it in a variable?


I tried:

$comportRequested = Run(@ComSpec & ' /c ' & """" & $PathTOS428cl & "tos428cs.bat""  getport""", $PathTOS428cl, @SW_HIDE)

however when I read value from $comportRequested it gives me back a different number each time, like 1162, 1728, etc..



Edited by gnolivos
Link to comment
Share on other sites

Thanks.  Still not sure about adding snippet code includes...  my main code is 30 lines, so Im looking to just add a few lines and learn how to do it.

I realize now I am looking at the PID number thanks :)

Can you help me rewrite that code of mine to capture the output of the BAT file instead?

Link to comment
Share on other sites

I said BAT to be generic...  its actualy an EXE that runs in command line mode.     I would really like to simply catch the output ins a few lines, but if that's not realistic I will find another way.  not trying to error handle much etc.

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

  • Recently Browsing   0 members

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