Execle ruby process from C?

Hello, I’m playing with a small http server written in C & Ruby CGI and
there is something wrong

if(execle("/usr/bin/ruby", “/usr/bin/ruby” " test.rb", NULL, NULL) ==
-1)
{
wlog(“error execle”);
exit(EXIT_FAILURE);
}

  • the C program did a chdir to the directory where test.rb can be found.
  • ps ae gives
    18133 pts/5 S+ 0:00 /usr/bin/ruby test.rb

test.rb contains just one line -> print “hello”

But when execle, ruby never returns… I mean, the server can be
interrupted with a CONTROL/C and gives /usr/bin/ruby test.rb: Interrupt

I don’t understand why…

I have to say that stdout and stdin are redirected to pipes - I tried
with some unix executables like ‘ls’ and it works

What is the difference with ruby executable ?

Thanks

I forgot to say that print ‘hello’ has not effect…

Zouplaz wrote:

Hello, I’m playing with a small http server written in C & Ruby CGI and
there is something wrong

if(execle("/usr/bin/ruby", “/usr/bin/ruby” " test.rb", NULL, NULL) ==
-1)
{
wlog(“error execle”);
exit(EXIT_FAILURE);
}

What is the difference with ruby executable ?

I may be mistaken because 1. I don’t have your full piece of code or 2.
I’m not very up-to-date with C.

But simply running …/ruby test.rb and test.rb only has print “hello” in
it, the output would be to your shell/terminal…not your http server
o_O

Correct me if I’m wrong and I’ll try to help the best I can. Post the
code to your http server and that would probably help alot.

Regards,

  • Mac

The second string is concatenated at compile time into
“/usr/bin/ruby test.rb”, so you execute ruby with only that one
argument, which is counted as the program name. Therefore ruby
waits script from stdin.

The HTTP server shouldn’t be waiting for stdin because test.rb never
calls for it. The server isn’t returning a value because it isn’t being
sent to the server, it’s being sent to the shell. If it was waiting for
input from stdin then hitting enter would return an input
value…nil…and it would return as such.

  • Mac

Hi,

At Mon, 16 Mar 2009 04:32:42 +0900,
Zouplaz wrote in [ruby-talk:331208]:

if(execle("/usr/bin/ruby", “/usr/bin/ruby” " test.rb", NULL, NULL) == -1)

The second string is concatenated at compile time into
“/usr/bin/ruby test.rb”, so you execute ruby with only that one
argument, which is counted as the program name. Therefore ruby
waits script from stdin.

Hi,

At Mon, 16 Mar 2009 12:59:51 +0900,
Michael L. wrote in [ruby-talk:331241]:

The second string is concatenated at compile time into
“/usr/bin/ruby test.rb”, so you execute ruby with only that one
argument, which is counted as the program name. Therefore ruby
waits script from stdin.

The HTTP server shouldn’t be waiting for stdin because test.rb never
calls for it.

Correct, but OP’s code doesn’t any arguments to /usr/bin/ruby.
So ruby expects that the script will be given from stdin.

That is, I meant a bug about string literal concatenation. It
should be:

if(execle("/usr/bin/ruby", “/usr/bin/ruby”, “test.rb”, NULL, NULL) ==
-1)

Note that a comma between “/usr/bin/ruby” and “test.rb”, and
stripping a leading space from " test.rb", also.