On Fri, 12 Nov 2010 22:50:32 -0500, Cai Inception <cai.inception / gmail.com> wrote in <422bf4524ffd3e8cb2b513afdca90793 / ruby-forum.com>: >Charles Calvert wrote in post #960600: >> You can do this, but you'll need to use the Win32 API to attach to a >> console (command shell) and be able to read and write to its STDIN and >> STDOUT. See the links below: >> >> <http://www.dreamincode.net/code/snippet921.htm> >> <http://www.halcyon.com/~ast/dload/guicon.htm> >> <http://msdn.microsoft.com/en-us/library/ms681944%28VS.85%29.aspx> >> >> The first two are links to examples, and the last is to the MSDN >> documentation. It's been a number of years since I did this, but it's >> the technique that Visual Studio uses to run the command-line >> compilers and pipe their output back into the IDE. > >Thanks Charles, this looks promising. You're welcome. >One little question is whether the ruby program need to create another >process for the new console? the MSDN doc says "A process can be >associated with only one console, so the AllocConsole function fails if >the calling process already has a console. A process can use the >FreeConsole function to detach itself from its current console, then it >can call AllocConsole to create a new console or AttachConsole to attach >to another console.If the calling process creates a child process, the >child inherits the new console." That's a good question. I've always done this from GUI apps where the use case was the same as Visual Studio's. As a result, the application didn't have a console allocated. I guess it depends on what your use case is. Are you running the Ruby app via the MRI from a console, or is it a web app running via Apache/Nginx/etc.? In the latter case, I wouldn't think that you'd have a console allocated to the app. You could always call AllocConsole as a test to see what happens. If your case is the former, then Jeremy Boop's suggestion might be the way to go. When I wrote my original reply, I was thinking of a GUI or webapp controlling the console app. -- Charles Calvert | Software Design/Development Celtic Wolf, Inc. | Project Management http://www.celticwolf.com/ | Technical Writing (703) 580-0210 | Research