简体   繁体   English

如何在vim的ruby界面中从ruby的shell命令重定向错误流?

[英]How can I redirect the error stream from ruby's shell commands in vim's ruby interface?

I want to use the rake module from vim's ruby interface to run rake files. 我想使用vim的ruby界面中的rake模块来运行rake文件。 When a rake task uses sh to call shell commands, the output goes directly to the terminal - it doesn't go through ruby's $stdout and $stderr - when I try to redirect $stdout and $stderr the output doesn't go to where I redirect it. 当rake任务使用sh调用shell命令时,输出将直接到达终端-它不会通过ruby的$stdout$stderr当我尝试重定向$stdout$stderr ,输出不会转到其中我重定向。

Now, in vim, that output does not go to vim's terminal - it goes to the terminal that launched vim! 现在,在vim中,该输出不会发送到vim的终端-它会发送到启动vim的终端!

stdout is not a problem, because rake prints it where I want it. stdout没问题,因为rake将其打印在我想要的位置。 However, if I try to use the rake module from vim's ruby interface, I don't want the error output to go to the terminal who called vim(which is hidden when running gVim and awkward when running shell vim) - I want it to go into something I can read via ruby or vimscript(so I can parse the error message) 但是,如果我尝试从vim的ruby界面使用rake模块,我不希望错误输出到调用vim的终端(在运行gVim时隐藏,而在运行shell vim时尴尬)-我希望它进入我可以通过ruby或vimscript读取的内容(以便我可以解析错误消息)

So, I'm looking for a way to: 因此,我正在寻找一种方法:

  • Read\\Redirect stderr of ruby's shell calls, or 读取\\重定向ruby的shell调用的stderr ,或者
  • Read\\redirect the stderr that vim sends to the shell that called it. 读取\\重定向vim发送的stderr到调用它的shell。

Is it possible? 可能吗?

If you use 2> when calling Ruby or rake, it will output stderr to where you want it. 如果在调用Ruby或rake时使用2> ,它将stderr到您想要的位置。

Will output error to console: 将错误输出到控制台:

ruby -e "raise 'exception'" > output

Will output error out file called output : 将输出错误输出文件称为output

ruby -e "raise 'exception'" 2> output

Hopefully this helps! 希望这会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM