Hiding the CMD Window/Ruby Interpreter with Win32API

Z

Zach Dennis

I spent the last hour figuring out how to hide the cmd.exe (dos) window/ruby
interpreter when running my ruby script. I didn't see any direct answers to
this question so here is how I got it to work.


require 'Win32API'

getConsoleWindow = Win32API.new("kernel32" , "GetConsoleWindow" , [] , 'L')
ptr_to_console = getConsoleWindow.call()
wndConsole = Win32API.new( "user32" , "ShowWindow" , ['p' , 'i'] , 'i' )
bl = wndConsole.call( ptr_to_console , 1 )


To do a quick test you can do:


require 'Win32API'
require 'tk'

getConsoleWindow = Win32API.new("kernel32" , "GetConsoleWindow" , [] , 'L')
ptr_to_console = getConsoleWindow.call()
wndConsole = Win32API.new( "user32" , "ShowWindow" , ['p' , 'i'] , 'i' )
wndConsole.call( ptr_to_console , 1 )
Tk.mainloop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,221
Latest member
TrinidadKa

Latest Threads

Top