Run a command. Write the command to stdout before running it. Wait until the command finishes execution. :param cmd: command to run. LF entries are magic get skipped. :type cmd: List[str] :param cmd_file: if not None, write the command to be run to that fi
(
self,
cmd,
cmd_file=None,
out_file=None,
show_stdout=True,
show_cmd=True,
extra_env=None,
extra_paths=None,
delete_env=None,
raise_on_failure=True,
**kwargs
)
| 138 | os.chmod(cmd_file, st.st_mode | stat.S_IXUSR) |
| 139 | |
| 140 | def run_cmd( |
| 141 | self, |
| 142 | cmd, |
| 143 | cmd_file=None, |
| 144 | out_file=None, |
| 145 | show_stdout=True, |
| 146 | show_cmd=True, |
| 147 | extra_env=None, |
| 148 | extra_paths=None, |
| 149 | delete_env=None, |
| 150 | raise_on_failure=True, |
| 151 | **kwargs |
| 152 | ): |
| 153 | ''' |
| 154 | Run a command. Write the command to stdout before running it. |
| 155 | |
| 156 | Wait until the command finishes execution. |
| 157 | |
| 158 | :param cmd: command to run. LF entries are magic get skipped. |
| 159 | :type cmd: List[str] |
| 160 | |
| 161 | :param cmd_file: if not None, write the command to be run to that file |
| 162 | :type cmd_file: str |
| 163 | |
| 164 | :param out_file: if not None, write the stdout and stderr of the command the file |
| 165 | :type out_file: str |
| 166 | |
| 167 | :param show_stdout: wether to show stdout and stderr on the terminal or not |
| 168 | :type show_stdout: bool |
| 169 | |
| 170 | :param extra_env: extra environment variables to add when running the command |
| 171 | :type extra_env: Dict[str,str] |
| 172 | |
| 173 | :return: exit status of the command |
| 174 | :rtype: int |
| 175 | ''' |
| 176 | if out_file is not None: |
| 177 | stdout = subprocess.PIPE |
| 178 | stderr = subprocess.STDOUT |
| 179 | else: |
| 180 | if show_stdout: |
| 181 | stdout = None |
| 182 | stderr = None |
| 183 | else: |
| 184 | stdout = subprocess.DEVNULL |
| 185 | stderr = subprocess.DEVNULL |
| 186 | if extra_env is None: |
| 187 | extra_env = {} |
| 188 | if delete_env is None: |
| 189 | delete_env = [] |
| 190 | if 'cwd' in kwargs: |
| 191 | cwd = kwargs['cwd'] |
| 192 | else: |
| 193 | cwd = None |
| 194 | env = os.environ.copy() |
| 195 | env.update(extra_env) |
| 196 | if extra_paths is not None: |
| 197 | path = ':'.join(extra_paths) |
no test coverage detected