Returns the birth time for the file. If the platform doesn’t have birthtime, raises NotImplementedError
.
See File.birthtime
.
Returns the last change time, using directory information, not the file itself.
See File.ctime
.
Update the access and modification times of the file.
Same as Pathname#utime
, but does not follow symbolic links.
See File.lutime
.
Spawns the specified command on a newly allocated pty. You can also use the alias ::getpty
.
The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.
env
is an optional hash that provides additional environment variables to the spawned pty.
# sets FOO to "bar" PTY.spawn({"FOO"=>"bar"}, "printenv", "FOO") do |r, w, pid| p r.read #=> "bar\r\n" ensure r.close; w.close; Process.wait(pid) end # unsets FOO PTY.spawn({"FOO"=>nil}, "printenv", "FOO") do |r, w, pid| p r.read #=> "" ensure r.close; w.close; Process.wait(pid) end
command
and command_line
are the full commands to run, given a String
. Any additional arguments
will be passed to the command.
In the non-block form this returns an array of size three, [r, w, pid]
.
In the block form these same values will be yielded to the block:
r
A readable IO
that contains the command’s standard output and standard error
w
A writable IO
that is the command’s standard input
pid
The process identifier for the command.
This method does not clean up like closing IOs or waiting for child process, except that the process is detached in the block form to prevent it from becoming a zombie (see Process.detach
). Any other cleanup is the responsibility of the caller. If waiting for pid
, be sure to close both r
and w
before doing so; doing it in the reverse order may cause deadlock on some OSes.
Allocates a pty (pseudo-terminal).
In the block form, yields an array of two elements (master_io, slave_file
) and the value of the block is returned from open
.
The IO
and File
are both closed after the block completes if they haven’t been already closed.
PTY.open {|master, slave| p master #=> #<IO:masterpty:/dev/pts/1> p slave #=> #<File:/dev/pts/1> p slave.path #=> "/dev/pts/1" }
In the non-block form, returns a two element array, [master_io, slave_file]
.
master, slave = PTY.open # do something with master for IO, or the slave file
The arguments in both forms are:
master_io
the master of the pty, as an IO
.
slave_file
the slave of the pty, as a File
. The path to the terminal device is available via slave_file.path
IO#raw!
is usable to disable newline conversions:
require 'io/console' PTY.open {|m, s| s.raw! # ... }
Spawns the specified command on a newly allocated pty. You can also use the alias ::getpty
.
The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.
env
is an optional hash that provides additional environment variables to the spawned pty.
# sets FOO to "bar" PTY.spawn({"FOO"=>"bar"}, "printenv", "FOO") do |r, w, pid| p r.read #=> "bar\r\n" ensure r.close; w.close; Process.wait(pid) end # unsets FOO PTY.spawn({"FOO"=>nil}, "printenv", "FOO") do |r, w, pid| p r.read #=> "" ensure r.close; w.close; Process.wait(pid) end
command
and command_line
are the full commands to run, given a String
. Any additional arguments
will be passed to the command.
In the non-block form this returns an array of size three, [r, w, pid]
.
In the block form these same values will be yielded to the block:
r
A readable IO
that contains the command’s standard output and standard error
w
A writable IO
that is the command’s standard input
pid
The process identifier for the command.
This method does not clean up like closing IOs or waiting for child process, except that the process is detached in the block form to prevent it from becoming a zombie (see Process.detach
). Any other cleanup is the responsibility of the caller. If waiting for pid
, be sure to close both r
and w
before doing so; doing it in the reverse order may cause deadlock on some OSes.
This method is called when weak warning is produced by the parser. fmt
and args
is printf style.
This method is called when strong warning is produced by the parser. fmt
and args
is printf style.
Parses src
and create S-exp tree. Returns more readable tree rather than Ripper.sexp_raw
. This method is mainly for developer use. The filename
argument is mostly ignored. By default, this method does not handle syntax errors in src
, returning nil
in such cases. Use the raise_errors
keyword to raise a SyntaxError
for an error in src
.
require 'ripper' require 'pp' pp Ripper.sexp("def m(a) nil end") #=> [:program, [[:def, [:@ident, "m", [1, 4]], [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil, nil, nil]], [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]
enable the socket option IPV6_V6ONLY
if IPV6_V6ONLY
is available.
Requests a connection to be made on the given remote_sockaddr
. Returns 0 if successful, otherwise an exception is raised.
remote_sockaddr
- the struct
sockaddr contained in a string or Addrinfo
object
# Pull down Google's web page require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 80, 'www.google.com' ) socket.connect( sockaddr ) socket.write( "GET / HTTP/1.0\r\n\r\n" ) results = socket.read
On unix-based systems the following system exceptions may be raised if the call to connect fails:
Errno::EACCES - search permission is denied for a component of the prefix path or write access to the socket
is denied
Errno::EADDRINUSE - the sockaddr is already in use
Errno::EADDRNOTAVAIL - the specified sockaddr is not available from the local machine
Errno::EAFNOSUPPORT - the specified sockaddr is not a valid address for the address family of the specified socket
Errno::EALREADY - a connection is already in progress for the specified socket
Errno::EBADF - the socket
is not a valid file descriptor
Errno::ECONNREFUSED - the target sockaddr was not listening for connections refused the connection request
Errno::ECONNRESET - the remote host reset the connection request
Errno::EFAULT - the sockaddr cannot be accessed
Errno::EHOSTUNREACH - the destination host cannot be reached (probably because the host is down or a remote router cannot reach it)
Errno::EINPROGRESS - the O_NONBLOCK is set for the socket
and the connection cannot be immediately established; the connection will be established asynchronously
Errno::EINTR - the attempt to establish the connection was interrupted by delivery of a signal that was caught; the connection will be established asynchronously
Errno::EISCONN - the specified socket
is already connected
Errno::EINVAL - the address length used for the sockaddr is not a valid length for the address family or there is an invalid family in sockaddr
Errno::ENAMETOOLONG - the pathname resolved had a length which exceeded PATH_MAX
Errno::ENETDOWN - the local interface used to reach the destination is down
Errno::ENETUNREACH - no route to the network is present
Errno::ENOBUFS - no buffer space is available
Errno::ENOSR - there were insufficient STREAMS resources available to complete the operation
Errno::ENOTSOCK - the socket
argument does not refer to a socket
Errno::EOPNOTSUPP - the calling socket
is listening and cannot be connected
Errno::EPROTOTYPE - the sockaddr has a different type than the socket bound to the specified peer address
Errno::ETIMEDOUT - the attempt to connect timed out before a connection was made.
On unix-based systems if the address family of the calling socket
is AF_UNIX
the follow exceptions may be raised if the call to connect fails:
Errno::EIO - an i/o error occurred while reading from or writing to the file system
Errno::ELOOP - too many symbolic links were encountered in translating the pathname in sockaddr
Errno::ENAMETOOLLONG - a component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters
Errno::ENOENT - a component of the pathname does not name an existing file or the pathname is an empty string
Errno::ENOTDIR - a component of the path prefix of the pathname in sockaddr is not a directory
On Windows systems the following system exceptions may be raised if the call to connect fails:
Errno::ENETDOWN - the network is down
Errno::EADDRINUSE - the socket’s local address is already in use
Errno::EINTR - the socket was cancelled
Errno::EINPROGRESS - a blocking socket is in progress or the service provider is still processing a callback function. Or a nonblocking connect call is in progress on the socket
.
Errno::EALREADY - see Errno::EINVAL
Errno::EADDRNOTAVAIL - the remote address is not a valid address, such as ADDR_ANY TODO check ADDRANY TO INADDR_ANY
Errno::EAFNOSUPPORT - addresses in the specified family cannot be used with with this socket
Errno::ECONNREFUSED - the target sockaddr was not listening for connections refused the connection request
Errno::EFAULT - the socket’s internal address or address length parameter is too small or is not a valid part of the user space address
Errno::EINVAL - the socket
is a listening socket
Errno::EISCONN - the socket
is already connected
Errno::ENETUNREACH - the network cannot be reached from this host at this time
Errno::EHOSTUNREACH - no route to the network is present
Errno::ENOBUFS - no buffer space is available
Errno::ENOTSOCK - the socket
argument does not refer to a socket
Errno::ETIMEDOUT - the attempt to connect timed out before a connection was made.
Errno::EWOULDBLOCK - the socket is marked as nonblocking and the connection cannot be completed immediately
Errno::EACCES - the attempt to connect the datagram socket to the broadcast address failed
connect manual pages on unix-based systems
connect function in Microsoft’s Winsock functions reference
Accepts a next connection. Returns a new Socket
object and Addrinfo
object.
serv = Socket.new(:INET, :STREAM, 0) serv.listen(5) c = Socket.new(:INET, :STREAM, 0) c.connect(serv.connect_address) p serv.accept #=> [#<Socket:fd 6>, #<Addrinfo: 127.0.0.1:48555 TCP>]