subprocess executing shell

Tim Arnold tim.arnold at
Wed Oct 21 17:24:37 CEST 2009

Hi, I'm writing a script to capture a command on the commandline and run it 
on a remote server.
I guess I don't understand subprocess because the code below exec's the 
user's .cshrc file even though by default shell=False in the Popen call.

Here's the code. I put a line in my .cshrc file: echo 'testing' which 
appears when I run this script on the remote host.
import os,sys,subprocess,shlex

def main():
    if action:
        action.insert(0,'rsh my_remotehost')
        p = subprocess.Popen(shlex.split(' '.join(action)))

if __name__ == '__main__':
    action = sys.argv[1:] or list()

Since the shell is executing in the child process anyway, is the only 
difference when using shell=True is that environment variables can be 
expanded in the command to be executed?

--Tim Arnold

More information about the Python-list mailing list