# Redirection Windows shell out to variable

**URL:** <https://www.ruby-forum.com/t/redirection-windows-shell-out-to-variable/178469>\
**Category:** Ruby\
**Created:** [November 5, 2009, 3:28am UTC](https://www.ruby-forum.com/t/redirection-windows-shell-out-to-variable/178469 "2009-11-05T03:28:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [November 5, 2009, 3:28am UTC](https://www.ruby-forum.com/t/redirection-windows-shell-out-to-variable/178469/1 "2009-11-05T03:28:43Z")

</div>

i want to execute Windows shell commands in my script so that the result  
came back in a variable and the new window of a Windows command line  
(MS-DOS-session) didn’t open.  
i write:

> a=‘dir’  
> system(a)  
> and i see out of ‘dir’ in window of command line, but i need to get it  
> into local variable.  
> And another question:  
> every time when rubyscript was run command line window is opening, even  
> if i compile script by exerb. Is it possible to hide window or run  
> script/rubyexefile without command line window and how if yes?

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [November 5, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/redirection-windows-shell-out-to-variable/178469/2 "2009-11-05T17:55:13Z")

</div>

On Wed, Nov 4, 2009 at 8:28 PM, born in USSR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And another question:  
> every time when rubyscript was run command line window is opening, even  
> if i compile script by exerb. Is it possible to hide window or run  
> script/rubyexefile without command line window and how if yes?

Run it with rubyw.exe, instead of ruby.exe.

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [November 5, 2009, 3:40am UTC](https://www.ruby-forum.com/t/redirection-windows-shell-out-to-variable/178469/3 "2009-11-05T03:40:04Z")

</div>

You can use the backtick (or backquote) operator ` which is ASCII  
character  
96:

e.g.

a = `dir`

which will give you a string with the stdout of the executed shell. Not  
that  
I would recommend using it with dir mind you. 🙂
