Python -- execution shell commands using a designated shells

66 views Asked by At

so I know python can execute shell commands using subprocess.call()

But I normally use tcsh, and I have a .tcshrc that loads a lot of environmental variables to make my shell comfortable.

How do I make my subprocess.call() realize that -- execute my commands in tcsh, load my .tcshrc file?

1

There are 1 answers

0
Dan Cornilescu On BEST ANSWER

Explicitly invoke tcsh to execute the respective cmds, like this (replace env with your specific cmd arg list:

~/> cat tst.py
#!/usr/bin/python -u
import subprocess
subprocess.call(['/usr/bin/tcsh', '-c', 'env'])
~/> ./tst.py | grep ^DISPLAY
DISPLAY=:0
~/>