# Invoking a batch file with Ruby on Windows

**URL:** <https://www.ruby-forum.com/t/invoking-a-batch-file-with-ruby-on-windows/65737>\
**Category:** Ruby\
**Created:** [August 21, 2006, 1:29am UTC](https://www.ruby-forum.com/t/invoking-a-batch-file-with-ruby-on-windows/65737 "2006-08-21T01:29:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 21, 2006, 1:29am UTC](https://www.ruby-forum.com/t/invoking-a-batch-file-with-ruby-on-windows/65737/1 "2006-08-21T01:29:48Z")

</div>

Hi

Does anyone know how I could invoke a Windows batch file (e.g.  
MyBatchFile.bat) and check the ERRORLEVEL environment variable after the  
batch file completes execution.

Thanks

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 21, 2006, 2:05am UTC](https://www.ruby-forum.com/t/invoking-a-batch-file-with-ruby-on-windows/65737/2 "2006-08-21T02:05:49Z")

</div>

On 8/21/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi
> 
> Does anyone know how I could invoke a Windows batch file (e.g.  
> MyBatchFile.bat) and check the ERRORLEVEL environment variable after the  
> batch file completes execution.
> 
> Thanks

1. Try:

- `MyBatchFile.bat`
- system “MyBatchFile.bat”
- the same but with “cmd /c MyBatchFile.bat” (or /k , I don’t remember  
exactly)

$? should contain the errorlevel (exit status)

I’m writing out of my head, if that won’t help, just ask again,  
tomorrow (i.e. in 10 hours) I can provide the right solution from my  
code.

J.
