# Is there a class that can control the command window

**URL:** <https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801>\
**Category:** Ruby\
**Created:** [November 21, 2006, 10:09am UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801 "2006-11-21T10:09:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliviabean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@oliviabean](https://www.ruby-forum.com/u/oliviabean)\
**Post date:** [November 21, 2006, 10:09am UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801/1 "2006-11-21T10:09:52Z")

</div>

I use ruby to do testing.  
There are some scenario that look like this:

1. Do some navigation in the web browser and do some operation in it
2. run some command, especially telnet to another machine and then run  
the commands
3. operate the browser again
4. run command in the telnet window again.

Now I use watir(Web application Testing in Ruby) to do navigation and  
operations in the IE browser, the script look like this:  
$ie.goto(“[http://localhost:8080](http://localhost:8080)”)  
$ie.frame(“basefrm”).button(:value,“Add Report”).click()

And what I need exactly is a similar ruby lib that I can use to write  
the script like this style:  
cmdWindow.InputCommand(“net user newUser /add”)

I know that I can use NET::Telnet if I want to do telnet related  
operations, and when executing the local commands, may use system(cmd),  
but I want to identify the specified command window, and run the  
following commands in that window.

I wonder whether I have made the questiong clear.

---

<div class="post-metadata">

**Author:** ![oliviabean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@oliviabean](https://www.ruby-forum.com/u/oliviabean)\
**Post date:** [November 21, 2006, 12:38pm UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801/2 "2006-11-21T12:38:42Z")

</div>

The following api in Ruby provides you a way to run OS cmd in cmd  
window:  
exec(command [, arg, …]);

Rgds,

---

<div class="post-metadata">

**Author:** ![oliviabean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@oliviabean](https://www.ruby-forum.com/u/oliviabean)\
**Post date:** [November 22, 2006, 2:45am UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801/3 "2006-11-22T02:45:37Z")

</div>

shiwei zhang wrote:

> The following api in Ruby provides you a way to run OS cmd in cmd  
> window:  
> exec(command [, arg, …]);
> 
> Rgds,

No, I know exec and system is the method to run OS cmd in cmd window,  
but what I need is a class that can represent the command window.

There is a ruby lib vruby that can represent the windows GUI such as  
form, dialog, but I didn’t see one that can represent the command  
window/command prompt.

---

<div class="post-metadata">

**Author:** ![oliviabean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@oliviabean](https://www.ruby-forum.com/u/oliviabean)\
**Post date:** [November 22, 2006, 6:23am UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801/4 "2006-11-22T06:23:55Z")

</div>

Olivia D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> No, I know exec and system is the method to run OS cmd in cmd window,  
> but what I need is a class that can represent the command window.
> 
> There is a ruby lib vruby that can represent the windows GUI such as  
> form, dialog, but I didn’t see one that can represent the command  
> window/command prompt.

It sounds as though you’re looking for Win32::Console

[http://rubyforge.org/projects/win32console/](http://rubyforge.org/projects/win32console/)

It’s a little bit out of date, so you’ll need to compile a new version  
for whatever version of ruby you have.

---

<div class="post-metadata">

**Author:** ![oliviabean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@oliviabean](https://www.ruby-forum.com/u/oliviabean)\
**Post date:** [November 22, 2006, 6:43am UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801/5 "2006-11-22T06:43:37Z")

</div>

Daniel M. wrote:

> Olivia D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> > No, I know exec and system is the method to run OS cmd in cmd window,  
> > but what I need is a class that can represent the command window.
> > 
> > There is a ruby lib vruby that can represent the windows GUI such as  
> > form, dialog, but I didn’t see one that can represent the command  
> > window/command prompt.
> 
> It sounds as though you’re looking for Win32::Console
> 
> [http://rubyforge.org/projects/win32console/](http://rubyforge.org/projects/win32console/)
> 
> It’s a little bit out of date, so you’ll need to compile a new version  
> for whatever version of ruby you have.

Thanks, Daniel.  
I did a quick research on Win32::Console, and it seems that the  
Win32::Console objects represents the console window the ruby script is  
run in, isn’t it?  
If so, I’m afraid it is still not exactly what I want,☹

---

<div class="post-metadata">

**Author:** ![oliviabean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@oliviabean](https://www.ruby-forum.com/u/oliviabean)\
**Post date:** [November 22, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/is-there-a-class-that-can-control-the-command-window/76801/6 "2006-11-22T13:12:30Z")

</div>

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

> And what I need exactly is a similar ruby lib that I can use to write  
> the script like this style:  
> cmdWindow.InputCommand(“net user newUser /add”)

If you don’t find anything, you could probably use popen4 as the basis  
for writing your own:

[http://popen4.rubyforge.org/](http://popen4.rubyforge.org/)

martin
