0

I read that os.system() shall be replaced by subprocess.call(), so I tried to use that. I am reading environment variables with

parallelrun = os.environ['PARALLEL_RUN']
aims = os.environ['AIMS_COMMAND']

and want to run it then with

with open(outfile, 'w') as f:
    subprocess.call([parallelrun, aims], stdout=f)

I haven't saved the error message, but it seemed to fail somewhere in the subprocess module. I think running it with shell=True works but makes the script more vulnerable. I do not understand why the variables which were specified in the same script do not expand without the shell. Any ideas?

quarky
  • 333
  • 1
  • 2
  • 12
  • Can you specify what exactly `parallelrun` and `aims` are? Generally the first argument in the list is the command, and then the parameters. Also, since you already got the environment variables, there is no need to expand them (with using `$` and `shell=True`). Check out [this](http://stackoverflow.com/a/3172488/5762711) answer also. – alexpeits Jan 18 '17 at 08:43
  • `parallelrun` contains a command like `mpirun` and `aims` the path to an executable. I wanted to avoid the `shell=True` for security issues. – quarky Jan 18 '17 at 09:44
  • Then I don't think there is a problem with the call, but rather with the execution of the `parallelrun` command. It would be helpful if you posted the traceback. – alexpeits Jan 18 '17 at 12:10
  • Don't have it. The thing is that using `os.system(parallelrun + ' ' + aims ' > ' outfile)` works perfectly fine. – quarky Jan 19 '17 at 09:28

0 Answers0