netinvent / command_runner

Substitute for subprocess that handles all hassle that comes from different platform and python versions, and allows live stdout and stderr capture for background job/interactive GUI programming ;)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add environment variables with command runner

MilanAssuied opened this issue · comments

Hi,

I am trying to run the following windows command with command runner:

set TOTO=1 && <run some executable here>

This should create a temporary env variable that will be accessible during the time that some executable runs.
However, I got an error "file not found: [WinError 2] The system cannot find the file specified:"

That may be because set is not a file but an internal command ?
Either way, I would need to execute it, is there a solution ?

Actually, that's not command_runner's job.
The way to accomplish this is:

import os
from command_runner import command_runner

os.environ['TOTO'] = "1"
exit_code, output = command_runner(''some executable here")

EDIT: You could also run with shell=True to support your initial statement, but the Pythonic version is safer.