Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>use backticks when you want to easily capture the output of a program in a variable. you probably only want to use this for short-running programs, because this will block.</p></li> <li><p><code>system</code> is convenient in two different cases:</p> <p>a. You have a long running program and you want the output to print as it runs (e.g. <code>system("tar zxvf some_big_tarball.tar.gz")</code>)</p> <p>b. <code>system</code> can bypass the shell expansion like <code>exec</code> (compare the output of <code>system "echo *"</code> and <code>system "echo", "*"</code>)</p> <p>system blocks until the subprocess has exited.</p></li> <li><p><code>fork</code> has a couple different use cases as well:</p> <p>a. You want to run some ruby code in a separate process (e.g. <code>fork { .... }</code></p> <p>b. You want to run a child process (or different program) without blocking progress of your script <code>fork { exec "bash" }</code>.</p> <p><code>fork</code> is your friend if you want to daemonize your program.</p></li> <li><p><code>IO.popen</code> is useful when you need to interact with the standard out and standard in of a program. Note that it doesn't capture standard err, so you need to redirect that with <code>2&gt;&amp;1</code> if you care about that.</p></li> <li><p><code>popen3</code> gives you a separate file descriptor for standard error (for when you need to capture that separately from standard out)</p></li> <li><p><code>PTY.spawn</code> is necessary when you want the spawned program to behave like you are running from the terminal. See the difference of <code>grep --color=auto pat file</code> when spawned with <code>system</code> vs <code>PTY.spawn</code></p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload