简体   繁体   English

红宝石命令的输出未显示在STDOUT中

[英]Output from ruby command is not shown in STDOUT

I have the following script that outputs the name of a file that is being rendered as I make changes to another file: 我有以下脚本,该脚本输出在更改另一个文件时正在渲染的文件的名称:

jade --watch --pretty index.jade

Since I use this a lot in my project I decided to create a rake task that does this. 由于我在项目中经常使用此工具,因此我决定创建一个执行此任务的rake任务。 But when I start the rake task the files get rendered but I no longer see the output. 但是,当我开始执行rake任务时,文件已渲染,但我不再看到输出。

I am aware that the output is somehow streamed to the STDOUT in this case which seems to behave differently than just executing say an ls command. 我知道在这种情况下,输出会以某种方式流式传输到STDOUT,这似乎与仅执行一个ls命令不同。

This is my Rakefile: 这是我的Rakefile:

desc 'Watch .jade files'
task :watch do
  puts `jade --watch --pretty index.jade`
end

The reason why you're not seeing any output is that jade will block while it's running and only return when you kill it. 之所以看不到任何输出,是因为jade在运行时会阻塞,并且只有在杀死它时才会返回。 If you were to kill it, you'd see the puts in effect. 如果要杀死它,您将看到puts生效。

What you want is to use system 你想要的是使用system

system("jade --watch --pretty index.jade")

Which will use your process's STDOUT. 哪个将使用您进程的STDOUT。

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

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