Ruby系统调用(在Windows上),没有弹出命令提示符 [英] Ruby system call (on windows) without a popup command prompt

查看:85
本文介绍了Ruby系统调用(在Windows上),没有弹出命令提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试整理一个进程,该进程从使用rubyw.exe(1.8.7)执行的ruby脚本内部使用多个系统调用.

I am trying to tidy up a process that uses multiple system calls from inside a ruby script executed using rubyw.exe (1.8.7).

据我了解,rubyw.exe的主要原因是它没有弹出命令提示符来分散用户的注意力.但是,看来该进程中的系统调用仍然会生成这些弹出窗口,这对于该进程脚本的用户来说是非常分散注意力的.

As far as I can understand the main reason for rubyw.exe is that it doesn't pop up a command prompt to distract the user. However it appears that the system calls from within that process still do generate these popups which is very distracting for the users of this process script.

有人知道该怎么做吗?

在SO上有很多与此类似的问题,但没有一个可以完全回答这个问题,如果我使用的是python,则此问题/答案将有所帮助(

There are lots of questions similar to this on SO but none which quite answers this, if I was using python this questions/answer would help (http://code.activestate.com/lists/python-list/46042/) but so far my searching hasn't found a way to accomplish this with ruby.

更新:这里有这个线程在Windows上隐藏curl窗口但是唯一可行的解​​决方案也不允许您获得标准输出.

UPDATE: There is this thread here Hiding curl Window on Windows which is close but the only working solution there doesn't also allow you to get the standard output.

推荐答案

我最终选择了win32-open3 gem.由于fork没有在Windows系统上实现,因此您无法使用内置的open3,并且需要执行

I ended up going with the win32-open3 gem. Because fork isn't implemented on windows systems you can't use the built in open3 and you'll need to do a

gem install win32-open3

但是,它带有可以传递给call方法的标志,尤其是

However this comes with flags that you can pass to the call method, in particular

open3的Windows版本有一些区别(哪一个也适用于Open4.popen4)-模式标志和显示标志.为了模式下,您可以将"t"(文本,默认值)或"b"(二进制)指定为第二个论点.对于显示标志,您可以指定true或false,是否显示控制台窗口,具体取决于您的值经过.默认值为false .

There are a couple of differences in the Windows version for open3 (which also apply to Open4.popen4) - the mode flag and the show flag. For the mode, you can specify either 't' (text, the default) or 'b' (binary) as a second argument. For the show flag, you can specify either true or false, which will show the console window, or not, depending on the value you pass. The default is false.

使用此特定脚本的用户不再受到不断窃取焦点的15 cmd窗口的轰炸,所以....赢了吗?

Users of this particular script are no longer bombarded with 15 cmd windows that constantly steal focus, so .... win?

这篇关于Ruby系统调用(在Windows上),没有弹出命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆