Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand your question right, I think you're making this far too complicated. <code>os.fork()</code> is for multiprocessing, not for running a program in the background.</p> <p>Let's say for the sake of discussion that you wanted to run <code>program.sh</code> and collect what it sends to standard output. To do this with fabric, create locally:</p> <p>fabfile.py:</p> <pre><code>from fabric.api import run def runmyprogram(): run('./program.sh &gt; output 2&gt; /dev/null &lt; /dev/null &amp;') </code></pre> <p>Then, locally, run:</p> <pre><code>fab -H remotebox runmyprogram </code></pre> <p>The program will execute remotely, but fabric will not wait for it to finish. You'll need to harvest the output files later, perhaps using scp. The "&amp;" makes this run in the background on the remote machine, and output redirection is necessary to <a href="http://docs.fabfile.org/en/1.0.1/faq.html#why-can-t-i-run-programs-in-the-background-with-it-makes-fabric-hang" rel="nofollow">avoid a hung fabric session</a>.</p> <p>If you don't need to use fabric, there are easier ways of doing this. You can ssh individually and run</p> <pre><code>nohup ./program.sh &gt; output &amp; </code></pre> <p>then come back later to check output.</p> <p>If this is something that you'll do on a regular basis, this might be the better option, since you can just set up a cron job to run every so often, and then collect the output whenever you want.</p> <p>If you'd rather not harvest the output files later, you can use:</p> <p>fabfile.py:</p> <pre><code>from fabric.api import run def runmyprogram(): run('./program.sh') </code></pre> <p>Then, on your local machine:</p> <pre><code>fab -H remotebox runmyprogram &gt; output &amp; </code></pre> <p>The jobs will run remotely, and put all their output back into the local output file. This runs in the background on your local machine, so you can do other things. However, if the connection between your local and remote machines might be interrupted, it's better to use the first approach so the output is always safely stored on the remote machines.</p>
 

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