locked
How to export an environment variable from command line ? RRS feed

  • Question

  • Hello,

    I have build a python application which run some processes(or executable or other python scripts) using subprocess.

    i.e.

    subprocess.call(["xyz.py"], shell=True, stdout=log_file, stderr=log_file)

    Above call throws an error as "xyz.py is not recognized as an internal or external command." I added the location of xyz.py into path variable inside a batch script which I used to run before running the script.

     set PATH=D:\path of xyz:%PATH%

    But As subprocess executes a script into anther child shell, This setting is not available in child shell (or sub-shell) used by python script.

    How can I make this PATH setting available to sub-shell also ?

    Monday, June 2, 2014 7:25 AM

Answers

  • Maybe it is easier to change the first command to:

        subprocess.call(["D:\path of xyz\xyz.py"], . . . );

    Have you asked the Python experts too?

    • Marked as answer by Ronex Sunday, July 6, 2014 5:33 AM
    Monday, June 2, 2014 8:32 AM

All replies

  • Maybe it is easier to change the first command to:

        subprocess.call(["D:\path of xyz\xyz.py"], . . . );

    Have you asked the Python experts too?

    • Marked as answer by Ronex Sunday, July 6, 2014 5:33 AM
    Monday, June 2, 2014 8:32 AM
  • Rather than going into much details I have used explicit path by referring only one environment variable of the shell where application is running.

    i.e.  As xyz.py will be in a specific location of my repository, I am setting path of root_dir:

          set root_dir=<path_of_root_dir>

          And then,

          subprocess.call([os.path.join(os.environ['roo_dir'], 'dir', 'xyz.py')], ...)

    Sunday, July 6, 2014 5:38 AM