Hello, I have a question about Ruby program:
I write a hello world program using c++, which output “Hello world!”,
I compile it into hello.o. Now, I want to write a Ruby program, which can run
hello.o in it and catch the output “Hello world!”. What am I use in Ruby to do this?
Sheen Zan
zx@is.pku.edu.cn
2002-11-09
I write a hello world program using c++, which output "Hello world!",
I compile it into hello.o. Now, I want to write a Ruby program, which can run
hello.o in it and catch the output "Hello world!". What am I use in Ruby
to do this?
Well, if you want to call an external program you can use ``
igeon% cat a.c
#include <stdio.h>
main()
{
printf("Hello world !\n");
}
pigeon%
pigeon% cc a.c
pigeon%
pigeon% cat b.rb
#!/usr/bin/ruby
res = `a.out`
puts "result : #{res}"
pigeon%
pigeon% b.rb
result : Hello world !
pigeon%
Guy Decoux