public Method

Kernel.`(p1)

`cmd`     string

Returns the standard output of running cmd in a subshell. The built-in syntax %x{…} uses this method. Sets $? to the process status.

`date`                   #=> "Wed Apr  9 08:56:30 CDT 2003\n"
`ls testdir`.split[1]    #=> "main.rb"
`echo oops && exit 99`   #=> "oops\n"
$?.exitstatus            #=> 99

Source Code

/*
*  call-seq:
*     `cmd`    => string
*  
*  Returns the standard output of running _cmd_ in a subshell.
*  The built-in syntax <code>%x{...}</code> uses
*  this method. Sets <code>$?</code> to the process status.
*     
*     `date`                   #=> "Wed Apr  9 08:56:30 CDT 2003\n"
*     `ls testdir`.split[1]    #=> "main.rb"
*     `echo oops && exit 99`   #=> "oops\n"
*     $?.exitstatus            #=> 99
*/

static VALUE
rb_f_backquote(obj, str)
   VALUE obj, str;
{
   volatile VALUE port;
   VALUE result;
   OpenFile *fptr;

   SafeStringValue(str);
   port = pipe_open(str, 0, "r");
   if (NIL_P(port)) return rb_str_new(0,0);

   GetOpenFile(port, fptr);
   result = read_all(fptr, remain_size(fptr), Qnil);
   rb_io_close(port);

   return result;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.