Run command in sub process. Runs the command in a sub process with the variables from `env` added in the current environment variables. Parameters ---------- command: List[str] The command and it's parameters env: Dict The additional environment variables
(command: List[str], env: Dict[str, str])
| 166 | |
| 167 | |
| 168 | def run_command(command: List[str], env: Dict[str, str]) -> int: |
| 169 | """Run command in sub process. |
| 170 | |
| 171 | Runs the command in a sub process with the variables from `env` |
| 172 | added in the current environment variables. |
| 173 | |
| 174 | Parameters |
| 175 | ---------- |
| 176 | command: List[str] |
| 177 | The command and it's parameters |
| 178 | env: Dict |
| 179 | The additional environment variables |
| 180 | |
| 181 | Returns |
| 182 | ------- |
| 183 | int |
| 184 | The return code of the command |
| 185 | |
| 186 | """ |
| 187 | # copy the current environment variables and add the vales from |
| 188 | # `env` |
| 189 | cmd_env = os.environ.copy() |
| 190 | cmd_env.update(env) |
| 191 | |
| 192 | p = Popen(command, |
| 193 | universal_newlines=True, |
| 194 | bufsize=0, |
| 195 | shell=False, |
| 196 | env=cmd_env) |
| 197 | _, _ = p.communicate() |
| 198 | |
| 199 | return p.returncode |