记录进程输出
我使用方法system
来启动一个进程。该进程的 pid 存储在文件 worker.pid
中,
但是我需要生成该进程的日志,如何存储该进程的输出?
正在使用以下命令创建进程:
system "bundle exec rake resque:work >> ./resque.log QUEUE=* PIDFILE=#{pid_file} &"
PS:我使用的是 ruby 1.8,BACKGROUND=yes 不起作用。 PS2:Linux平台
I used the method system
to start a process. the pid of that process is being stored in a file worker.pid
however I need to generate the log of this process, how can I store the output of this process?
the process is being created with this command:
system "bundle exec rake resque:work >> ./resque.log QUEUE=* PIDFILE=#{pid_file} &"
P.S.: I am using ruby 1.8, BACKGROUND=yes won`t work.
P.S.2: platform linux
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您正在寻找的是 IO.popen
这可以让你分叉一个子进程并通过 IO 对象访问它的输出
我建议你阅读文档,
但您也可以写入流,并做各种聪明的事情。
Maybe what you're looking for is IO.popen
This lets you fork off a subprocess and access it's output via an IO object
I suggest you read the documentation,
but you can also write to the stream, and do all sorts of clever stuff.
如果我理解您想要正确实现的目标,那么您正在寻找 Open3 课程。 http://www.ruby-doc.org /stdlib-1.8.7/libdoc/open3/rdoc/Open3.html
If I'm understanding what you are trying to achieve correctly, you are looking for the Open3 class. http://www.ruby-doc.org/stdlib-1.8.7/libdoc/open3/rdoc/Open3.html