开发者

How to close command prompt Window in Ruby?

I need to close the command prompt window which I have opened in my ruby script using system("start cmd.exe")

I cannot use "exit" command as there is some batch file running in the comma开发者_Python百科nd prompt, I need to terminate that Window and close the command prompt.

Please help me to close Window.


I'd do something like:

cmdprompt = Process.spawn 'start cmd.exe' # open prompt
Process.kill 9, cmdprompt                 # close it

Not sure will it work for Windows, though.

There is gem win32-process that provides ability to handle external processes on Windows, try this:

require 'rubygems'
require 'win32/process'
cmdprompt = Process.create(:app_name => 'cmd')   # open
Process.kill 9, cmdprompt.process_id             # close

I have no ability to test it, but think it shoul work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜