Hide os.system command line call in python script
Question: I have a python script (myscript.py) that I am running on the linux server
like below:

python myscript.py

In my script I am using the system call, example below:

    
    
    os.system("./myprogram.pl -x 5 > results.out")
    

When I run myscript.py on the server whenever there is `os.system` call, the
command call is visible on the server. Is there a way to hide all the command
calls so that they are not displayed when they are called within the program
(`myscript.py`)? (This is not about hiding the output resulted in the command
calls within the program)


Answer: You can use a subprocess pipe instead of the os.system command:

    
    
    import subprocess;
    
    NewPipeObject = subprocess.Popen( [ './myprogram.pl -x 5 > results.out' ],
                                      stdout= subprocess.PIPE,
                                      stderr= subprocess.PIPE );
    

or you can take advantage of the list format of the arguments for the
subprocess pipe (it adds a space between each list element) and present them
as the following (which will be easier to generalize):

    
    
    import subprocess;
    
    NewPipeObject = subprocess.Popen( [ './myprogram.pl',
                                        '-x',
                                        '5',
                                        '>',
                                        'results.out' ],
                                      stdout= subprocess.PIPE,
                                      stderr= subprocess.PIPE );
    

Either way you're suppressing the outputs from `stdout` and `stderr` into the
pipe object (`NewPipeObject`).

