instance method
Kernel#`
(::String arg0) -> ::String
`command` → string
io.c
View on GitHub ↗
static VALUE
rb_f_backquote(VALUE obj, VALUE str)
{
VALUE port;
VALUE result;
rb_io_t *fptr;
StringValue(str);
rb_last_status_clear();
port = pipe_open_s(str, "r", FMODE_READABLE|DEFAULT_TEXTMODE, NULL);
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);
rb_io_fptr_cleanup_all(fptr);
RB_GC_GUARD(port);
return result;
}
Returns the $stdout output from running command in a subshell; sets global variable $? to the process status.
This method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Examples:
$ `date` # => "Wed Apr 9 08:56:30 CDT 2003\n" $ `echo oops && exit 99` # => "oops\n" $ $? # => #<Process::Status: pid 17088 exit 99> $ $?.exitstatus # => 99
The built-in syntax %x{...} uses this method.