Safely execute shell commands and get their output.
// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
- Health 100/100 with only 76 stars
- Around since 2010 and still shipping
- 91 watchers, more than its 76 stars
// how to help
// readme
SafeShell
SafeShell lets you execute shell commands and get the resulting output, but without the security problems of Rubyβs backtick operator.
Usage
Install gem:
gem install safe_shell
Use gem:
require 'safe_shell'
SafeShell.execute("echo", "Hello, world!")
SafeShell sets the $? operator to the process status, in the same manner as the backtick operator.
If the call is interrupted, by a timeout or a signal, SafeShell sends the command TERM, then KILL if it is still running a second later, and reaps it, so $? describes the terminated command. The call returns once the command has been reaped, normally up to a second after the interruption. Only the commandβs own process is signalled, not any processes it started. The exceptions: