I’m working on a build tool, and I need to execute various
compilers/linkers and capture their output (both stdout and stderr) for
Windows and Linux compilations (msvc & gcc).
The problem is I want the output to stderr and stdout to go to the same
pipe (same result as if you were running the program from the
command-line). I can use a hack like:
out = cmd /c \"#{cmdLine}\" >bs.out 2>&1
on windows and then simply read bs.out (which will contain both stdout
and stderr), but I’d prefer to avoid the overhead (and platform specific
code) of spawning cmd.exe to run another program.
I’d prefer to use something like popen, but in a way that lets me get a
single pipe I can read from that the process’s stdout & stderr pipes are
connected to.
Due to different compiler’s general messages and warnings/errors being
logged interchangably to stdout or stderr, it’s not really feasible to
have the pipes be separate.
I am currently reading the book ‘Programming Ruby’ and during this time
I want to write same scripts with the new stuff I’ve learned. At the
moment I search a smart way to copy a file and I want to say sorry but I
didn’t find a methode like FILE#copy(theNewFileName) or
FILE.copy(theOldFileName, theNewFileName). Is there another way to do
this?
One way I find:
open the file which I want to copy
read each line and write each one into the new file at a the place I
want to copy it…
But that is not so smart like the other stuff of ruby…
At last I want to say sorry for my bad english, it is so hard for me to
speak and write my native language and so there is no way for me to
write english a better way (-;
I’m working on a build tool, and I need to execute various
compilers/linkers and capture their output (both stdout and stderr) for
Windows and Linux compilations (msvc & gcc).
The problem is I want the output to stderr and stdout to go to the same
pipe (same result as if you were running the program from the
command-line). I can use a hack like:
out = cmd /c \"#{cmdLine}\" >bs.out 2>&1
on windows and then simply read bs.out (which will contain both stdout
and stderr), but I’d prefer to avoid the overhead (and platform specific
code) of spawning cmd.exe to run another program.
I’d prefer to use something like popen, but in a way that lets me get a
single pipe I can read from that the process’s stdout & stderr pipes are
connected to.
Due to different compiler’s general messages and warnings/errors being
logged interchangably to stdout or stderr, it’s not really feasible to
have the pipes be separate.
What about separate pipes, two threads reading them and putting messages
in a queue, and a third thread pulling messages in from the queue?
I’m working on a build tool, and I need to execute various
compilers/linkers and capture their output (both stdout and stderr) for
Windows and Linux compilations (msvc & gcc).
(…)
I’d prefer to use something like popen, but in a way that lets me get a
single pipe I can read from that the process’s stdout & stderr pipes are
connected to.
This works for me on Windows 2000, Ruby 1.8.0:
D:\Temp>type r.rb
def parent
IO.popen “ruby #{FILE} child 2>&1” do |io|
while line = io.gets
puts “got #{line}”
end
end
end
I am currently reading the book ‘Programming Ruby’ and during this time
I want to write same scripts with the new stuff I’ve learned. At the
moment I search a smart way to copy a file and I want to say sorry but I
didn’t find a methode like FILE#copy(theNewFileName) or
FILE.copy(theOldFileName, theNewFileName). Is there another way to do
this?
One way I find:
open the file which I want to copy
read each line and write each one into the new file at a the place I
want to copy it…
But that is not so smart like the other stuff of ruby…
At last I want to say sorry for my bad english, it is so hard for me to
speak and write my native language and so there is no way for me to
write english a better way (-;
I am currently reading the book ‘Programming Ruby’ and during this time
I want to write same scripts with the new stuff I’ve learned. At the
moment I search a smart way to copy a file and I want to say sorry but I
didn’t find a methode like FILE#copy(theNewFileName) or
FILE.copy(theOldFileName, theNewFileName). Is there another way to do
this?
One way I find:
open the file which I want to copy
read each line and write each one into the new file at a the place I
want to copy it…
But that is not so smart like the other stuff of ruby…
At last I want to say sorry for my bad english, it is so hard for me to
speak and write my native language and so there is no way for me to
write english a better way (-;
class Spawn
class << self; alias new; end
RUBY = File.join(Config::CONFIG[“bindir”], Config::CONFIG[“ruby_install_name”])
PROGRAM = <<-code
STDERR.reopen(STDOUT)
exec(*ARGV)
code
attr :out
def initialize argv @out = #{ RUBY } -e '#{ PROGRAM }' #{ argv.join(' ') }
end
end
The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”
/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================