From: Gavin Sinclair Date: 2002-08-16T16:24:04+09:00 Subject: Re: For Windows users only... Having bluntly stated my solution, let me elaborate by example. Below is a complete Cygwin transcript demonstrating: (a) running Ruby programs; (b) redirecting standard output; (c) redirecting standard error; (d) fortune. Before I get into it, can I ask a question? Am I missing out on anything by not using the "native" windows installation? Transacript follows after signoff. Cheers, Gavin The steady state of disks is full. -- Ken Thompson ---- Next three birthdays: John Brondum 2002-09-18 (in 33 days) David Wells 2002-09-21 (in 36 days) Ian Morris 2002-09-30 (in 45 days) Gavin Sinclair@NOSEDOG ~ $ cd /tmp Gavin Sinclair@NOSEDOG /tmp $ cat > demo.rb #!/usr/local/bin/ruby puts < output Gavin Sinclair@NOSEDOG /tmp $ cat output I'm a little vegemite As bright as bright can be We all enjoy our vegemite For breakfast, lunch and tea Gavin Sinclair@NOSEDOG /tmp $ cat > err.rb #!/usr/local/bin/ruby STDERR.puts "I'm nasty" STDOUT.puts "I'm nice" Gavin Sinclair@NOSEDOG /tmp $ ./err.rb I'm nasty I'm nice Gavin Sinclair@NOSEDOG /tmp B $ ./err.rb > /dev/null I'm nasty Gavin Sinclair@NOSEDOG /tmp C $ ./err.rb 2> /dev/null I'm nice D Gavin Sinclair@NOSEDOG /tmp $ fortune -o The problem with being best man at a wedding is that you never get a chance to prove it. Gavin Sinclair@NOSEDOG /tmp $ > At the command line, that is. > > Problem: When you run a .rb file from the > command line, you have to type a (potentially > lengthy) command. > > First idea: Wrap it in a batch file. > > However: Did you know that Windows is too dumb > to associate the stdout of a program with the > stdout of the batch file? I.e., if you have a > foo.bat file and you say "foo >outfile" it will > NOT work (at least not in older Windows versions... > I can't speak of NT, 2K, XP). > > Well, you can use "start" on Win98. Still kind of > a pain. > > My solution: > > Write a C program that will detect its own name and > directory; locate a corresponding Ruby program in > that same directory; read the #! line from the > beginning (usu. ignored in Win); and run the Ruby > program. It passes in the parameters, too. > > Note that you only have to compile once, since the > program knows its own name. You can just > copy fakeruby.exe myprog.exe > assuming there is a myprog.rb in that directory. > > I know, it's kind of an exercise in futility. But > if you want the code, here it is. It compiles fine > with djgpp. > > Feel free to criticize it or improve it. It's far > from perfect. For some reason, execvp() didn't work > for me. > > Cheers, > Hal > > [lovely-looking C code snipped]