Return (status,output) of executed command. Parameters ---------- command : str A concatenated string of executable and arguments. execute_in : str Before running command ``cd execute_in`` and after ``cd -``. use_shell : {bool, None}, optional If Tru
(command, execute_in='', use_shell=None, use_tee=None,
_with_python = 1, **env )
| 193 | return False |
| 194 | |
| 195 | def exec_command(command, execute_in='', use_shell=None, use_tee=None, |
| 196 | _with_python = 1, **env ): |
| 197 | """ |
| 198 | Return (status,output) of executed command. |
| 199 | |
| 200 | Parameters |
| 201 | ---------- |
| 202 | command : str |
| 203 | A concatenated string of executable and arguments. |
| 204 | execute_in : str |
| 205 | Before running command ``cd execute_in`` and after ``cd -``. |
| 206 | use_shell : {bool, None}, optional |
| 207 | If True, execute ``sh -c command``. Default None (True) |
| 208 | use_tee : {bool, None}, optional |
| 209 | If True use tee. Default None (True) |
| 210 | |
| 211 | |
| 212 | Returns |
| 213 | ------- |
| 214 | res : str |
| 215 | Both stdout and stderr messages. |
| 216 | |
| 217 | Notes |
| 218 | ----- |
| 219 | On NT, DOS systems the returned status is correct for external commands. |
| 220 | Wild cards will not work for non-posix systems or when use_shell=0. |
| 221 | |
| 222 | """ |
| 223 | log.debug('exec_command(%r,%s)' % (command,\ |
| 224 | ','.join(['%s=%r'%kv for kv in env.items()]))) |
| 225 | |
| 226 | if use_tee is None: |
| 227 | use_tee = os.name=='posix' |
| 228 | if use_shell is None: |
| 229 | use_shell = os.name=='posix' |
| 230 | execute_in = os.path.abspath(execute_in) |
| 231 | oldcwd = os.path.abspath(os.getcwd()) |
| 232 | |
| 233 | if __name__[-12:] == 'exec_command': |
| 234 | exec_dir = os.path.dirname(os.path.abspath(__file__)) |
| 235 | elif os.path.isfile('exec_command.py'): |
| 236 | exec_dir = os.path.abspath('.') |
| 237 | else: |
| 238 | exec_dir = os.path.abspath(sys.argv[0]) |
| 239 | if os.path.isfile(exec_dir): |
| 240 | exec_dir = os.path.dirname(exec_dir) |
| 241 | |
| 242 | if oldcwd!=execute_in: |
| 243 | os.chdir(execute_in) |
| 244 | log.debug('New cwd: %s' % execute_in) |
| 245 | else: |
| 246 | log.debug('Retaining cwd: %s' % oldcwd) |
| 247 | |
| 248 | oldenv = _preserve_environment( list(env.keys()) ) |
| 249 | _update_environment( **env ) |
| 250 | |
| 251 | try: |
| 252 | st = _exec_command(command, |
nothing calls this directly
no test coverage detected