0

I am set the environ using os module

import os
os.putenv('test','/usr/lib/jvm')
os.system('bash')

How to set using subprocess

import subprocess

NB: Please don't write a shell script and call using subprocess

  • 1
    Does this answer your question? [Python: Exporting environment variables in subprocess.Popen(..)](https://stackoverflow.com/questions/26643719/python-exporting-environment-variables-in-subprocess-popen) – Random Davis Oct 21 '20 at 17:20
  • @RandomDavis can you help in writing using subprocess –  Oct 21 '20 at 17:24
  • @RandomDavis tried with `import subprocess` subprocess.Popen('/usr/lib/jvm $test', shell=True, env=d).wait() –  Oct 21 '20 at 17:27
  • @Maws, if you [edit] the question to show a specific attempt that reflects _trying_ to use the linked duplicate's answer and not getting the expected results, that might then be a new, distinct, non-duplicative question. That said, please make sure that test is actually something _people other than you_ can be expected to successfully run without making assumptions about other things you did -- that's not the case for the code fragment in your comment above. – Charles Duffy Oct 23 '20 at 15:54
  • (to explain that "not the case" assertion: (1) on most systems, `/usr/lib/jvm` is a directory, not an executable, so it isn't expected to be something that can be executed ever; (2) you aren't showing `test` being inserted into `d`; (3) you aren't showing actual and expected output that would _reflect_ whether `test` is being successfully substituted by the shell -- though I'd expect running `/usr/lib/jvm` to _always_ fail, whether that substitution happens or not). – Charles Duffy Oct 23 '20 at 15:56

0 Answers0