How to run 'module load < > ' command from within python script
<p>I tried using <code>os.system()</code>, <code>subprocess.call()</code> and <code>subprocess.Popen()</code> {<em>with and without the option <code>shell=True</code></em>} to execute <code>module load ___</code> from within my python script. Even though the script runs successfully and it mentions that my module has been loaded in the terminal, I am unable to use it. I am working on a ssh client. The <code>module load _____</code> works fine when I run it directly as a command line.</p>

<p>I believe the problem is that both os.system and subprocess are running the command in a... well, subprocess. So the module is load successfully in the subprocess context and it exists immediately. No effect in python's process context though.</p>

<p>I'm not near a computer now to try it out, this should work:</p>

<p>run_py.sh:</p>

<pre><code>pyfile=$1
shift 1
python $pyfile $(tty) $@ &amp;
</code></pre>

<p>This will run your python file with the first argument a path to the current tty device, and all the other arguments follow.
Parse the arguments, save the tty device path to tty_dev. Now you can run:</p>

<pre><code>os.system('echo "module load &lt;&gt;" &gt; ' + tty_dev)
</code></pre>

python shell