# Logging stdout/stderr/stdin of an spawn process (Open4::spawn)

**URL:** <https://www.ruby-forum.com/t/logging-stdout-stderr-stdin-of-an-spawn-process-open4-spawn/134973>\
**Category:** Ruby\
**Created:** [April 16, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/logging-stdout-stderr-stdin-of-an-spawn-process-open4-spawn/134973 "2008-04-16T18:27:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Hames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecb155/32.png) [@Ed\_Hames](https://www.ruby-forum.com/u/Ed_Hames)\
**Post date:** [April 16, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/logging-stdout-stderr-stdin-of-an-spawn-process-open4-spawn/134973/1 "2008-04-16T18:27:16Z")

</div>

Hi dear rubyists,

I need to log all the input (typed by the user) and the stdout/stderr  
of a process. The #script method below should behave pretty much like  
the Unix script application. This way, my application can issue  
several commands, show their output to the user an let them whatever  
is needed.

def script cmd, log  
# prepare $stdin to save its content into log  
# prepare $stdout to save its content into log  
# prepare $stderr to save its content into log  
status = Open4::spawn cmd, ‘stdin’ =\> $stdin, ‘stdout’ =\>  
$stdout, ‘stderr’ =\> $stderr  
end

I’ve seen some implementations of a #tee function or Tee class, but  
they don’t seem to work with spawn. What would you suggest?

Thanks in advance,  
Ed
