# Wrapping interactive console program in Windows

**URL:** <https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784>\
**Category:** ruby-talk\
**Created:** [29 March 2004 07:11 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784 "2004-03-29T07:11:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Middleton1](https://avatars.discourse-cdn.com/v4/letter/e/47e85d/32.png) [@Edward\_Middleton1](https://rubytalk.org/u/Edward_Middleton1)\
**Post date:** [29 March 2004 07:11 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/1 "2004-03-29T07:11:28Z")

</div>

I am trying to write a wrapper for a program with an interactive shell,  
under windows. I am having problems with the process blocking  
permanently or repeating the last command. When it is like the following  
it loops forever on the puts.

IO.popen(“myprogram.exe”,“w+”) do |link|  
link.puts "command"  
link.close\_write  
result = link.readlines  
p result  
end

When I remove the close\_write it doesn’t loop but blocks on readlines. I  
can modify both the interactive program and the ruby wrapper library. I  
tried explicitly putting a \_flushall(); call and even a \_fcloseall( );  
in the interactive program but neither had any effect. How should this  
be done? Any advice or examples would be great.

Edward

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [29 March 2004 10:38 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/2 "2004-03-29T10:38:27Z")

</div>

Hi,

At Mon, 29 Mar 2004 16:11:28 +0900,  
Edward Middleton wrote in [ruby-talk:96019]:

> When I remove the close\_write it doesn’t loop but blocks on readlines. I  
> can modify both the interactive program and the ruby wrapper library. I  
> tried explicitly putting a \_flushall(); call and even a \_fcloseall( );  
> in the interactive program but neither had any effect. How should this  
> be done? Any advice or examples would be great.

At close\_write, your myprogram.exe reaches EOF. You have to  
check it.

> **···**
>
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Ben\_Giddings1](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Ben\_Giddings1](https://rubytalk.org/u/Ben_Giddings1)\
**Post date:** [29 March 2004 23:32 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/3 "2004-03-29T23:32:53Z")

</div>

Edward Middleton wrote:

> I am trying to write a wrapper for a program with an interactive shell,

You might want to look at rexpect.rb or expect.rb. I think expect.rb is  
distributed with Ruby, rexpect.rb is available on rubyforge.

Ben

---

<div class="post-metadata">

**Author:** ![Edward\_Middleton1](https://avatars.discourse-cdn.com/v4/letter/e/47e85d/32.png) [@Edward\_Middleton1](https://rubytalk.org/u/Edward_Middleton1)\
**Post date:** [30 March 2004 00:51 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/4 "2004-03-30T00:51:38Z")

</div>

Ben Giddings wrote:

> Edward Middleton wrote:
> 
> > I am trying to write a wrapper for a program with an interactive  
> > shell,
> 
> You might want to look at rexpect.rb or expect.rb. I think expect.rb  
> is distributed with Ruby, rexpect.rb is available on rubyforge.

I thought of that but It is not apear to be included with the windows  
version I have installed. Is there a windows version with expect support?

Edward

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [30 March 2004 02:03 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/5 "2004-03-30T02:03:09Z")

</div>

Hi,

At Tue, 30 Mar 2004 09:51:38 +0900,  
Edward Middleton wrote in [ruby-talk:96087]:

> > > I am trying to write a wrapper for a program with an interactive  
> > > shell,
> > 
> > You might want to look at rexpect.rb or expect.rb. I think expect.rb  
> > is distributed with Ruby, rexpect.rb is available on rubyforge.
> 
> I thought of that but It is not apear to be included with the windows  
> version I have installed. Is there a windows version with expect support?

Windows doesn’t pty support. I’d like to know how to create  
pseudo console on Windows, if it were possible.

> **···**
>
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Edward\_Middleton1](https://avatars.discourse-cdn.com/v4/letter/e/47e85d/32.png) [@Edward\_Middleton1](https://rubytalk.org/u/Edward_Middleton1)\
**Post date:** [30 March 2004 06:09 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/6 "2004-03-30T06:09:15Z")

</div>

I think this is how to do it.

> **[Microsoft Learn: Build skills that open doors in your career](https://learn.microsoft.com/en-us/)**
>
> Gain technical skills through documentation and training, earn certifications and connect with the community

Edward

> **···**
>
> [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > Hi,
> > 
> > At Tue, 30 Mar 2004 09:51:38 +0900, Edward Middleton wrote in  
> > [ruby-talk:96087]:
> > 
> > > > > I am trying to write a wrapper for a program with an interactive  
> > > > > shell, | | | You might want to look at rexpect.rb or expect.rb.  
> > > > > I think expect.rb | is distributed with Ruby, rexpect.rb is  
> > > > > available on rubyforge.
> > > 
> > > I thought of that but It is not apear to be included with the  
> > > windows version I have installed. Is there a windows version with  
> > > expect support?
> > 
> > Windows doesn’t pty support. I’d like to know how to create pseudo  
> > console on Windows, if it were possible.

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [30 March 2004 10:13 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/7 "2004-03-30T10:13:06Z")

</div>

Hi,

At Tue, 30 Mar 2004 15:09:15 +0900,  
Edward Middleton wrote in [ruby-talk:96102]:

> > > > > I am trying to write a wrapper for a program with an interactive  
> > > > > shell, | | | You might want to look at rexpect.rb or expect.rb.  
> > > > > I think expect.rb | is distributed with Ruby, rexpect.rb is  
> > > > > available on rubyforge.
> > > 
> > > I thought of that but It is not apear to be included with the  
> > > windows version I have installed. Is there a windows version with  
> > > expect support?
> > 
> > Windows doesn’t pty support. I’d like to know how to create pseudo  
> > console on Windows, if it were possible.
> 
> I think this is how to do it.
> 
> [Microsoft Learn: Build skills that open doors in your career](http://msdn.microsoft.com/library/en-us/dllproc/base/character_mode_applications.asp)

I didn’t mean how to use console, but how to provide console  
features to subprocess from a process.

> **···**
>
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Edward\_Middleton1](https://avatars.discourse-cdn.com/v4/letter/e/47e85d/32.png) [@Edward\_Middleton1](https://rubytalk.org/u/Edward_Middleton1)\
**Post date:** [31 March 2004 08:24 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/8 "2004-03-31T08:24:59Z")

</div>

I am not sure I am understanding but would this be what you are refering  
to. It allows you to create a new process in a new console or inherit  
the parents console.

> **[Microsoft Learn: Build skills that open doors in your career](https://learn.microsoft.com/en-us/)**
>
> Gain technical skills through documentation and training, earn certifications and connect with the community

It is also possiable to associate a console with a graphical application  
using

> **[Microsoft Learn: Build skills that open doors in your career](https://learn.microsoft.com/en-us/)**
>
> Gain technical skills through documentation and training, earn certifications and connect with the community

Edward Middleton

> **···**
>
> [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > > I think this is how to do it.
> > > 
> > > [Microsoft Learn: Build skills that open doors in your career](http://msdn.microsoft.com/library/en-us/dllproc/base/character_mode_applications.asp)
> > 
> > I didn’t mean how to use console, but how to provide console  
> > features to subprocess from a process.

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [1 April 2004 17:01 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/9 "2004-04-01T17:01:03Z")

</div>

Hi,

At Wed, 31 Mar 2004 17:24:59 +0900,  
Edward Middleton wrote in [ruby-talk:96204]:

> [1 \<text/plain; ISO-8859-1 (7bit)\>]  
> I am not sure I am understanding but would this be what you are refering  
> to. It allows you to create a new process in a new console or inherit  
> the parents console.

Default console provided by Windows quite differs from pty.

BTW, your original issue seems not to be concerned with pty at  
all. Have you read [ruby-talk:96023]?

> **···**
>
> > [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Edward\_Middleton1](https://avatars.discourse-cdn.com/v4/letter/e/47e85d/32.png) [@Edward\_Middleton1](https://rubytalk.org/u/Edward_Middleton1)\
**Post date:** [2 April 2004 01:53 UTC](https://rubytalk.org/t/wrapping-interactive-console-program-in-windows/10784/10 "2004-04-02T01:53:44Z")

</div>

I have read it but probably not understood. I realize it should not  
have a close\_write because I intend to continue using the processes  
stdin. The program does not terminate after processing the first  
command. Isn’t EOF only issued when the program terminates and closes  
its stdout?

Edward Middleton

> **···**
>
> [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > Default console provided by Windows quite differs from pty.
> > 
> > BTW, your original issue seems not to be concerned with pty at all.  
> > Have you read [ruby-talk:96023]?
> 
> [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > At close\_write, your myprogram.exe reaches EOF. You have to check  
> > it.
