Return (status,output) of executed command. .. deprecated:: 1.17 Use subprocess.Popen instead Parameters ---------- command : str A concatenated string of executable and arguments. execute_in : str Before running command ``cd execute_in`` and after
(command, execute_in='', use_shell=None, use_tee=None,
_with_python = 1, **env )
| 175 | os.environ[name] = value or '' |
| 176 | |
| 177 | def exec_command(command, execute_in='', use_shell=None, use_tee=None, |
| 178 | _with_python = 1, **env ): |
| 179 | """ |
| 180 | Return (status,output) of executed command. |
| 181 | |
| 182 | .. deprecated:: 1.17 |
| 183 | Use subprocess.Popen instead |
| 184 | |
| 185 | Parameters |
| 186 | ---------- |
| 187 | command : str |
| 188 | A concatenated string of executable and arguments. |
| 189 | execute_in : str |
| 190 | Before running command ``cd execute_in`` and after ``cd -``. |
| 191 | use_shell : {bool, None}, optional |
| 192 | If True, execute ``sh -c command``. Default None (True) |
| 193 | use_tee : {bool, None}, optional |
| 194 | If True use tee. Default None (True) |
| 195 | |
| 196 | |
| 197 | Returns |
| 198 | ------- |
| 199 | res : str |
| 200 | Both stdout and stderr messages. |
| 201 | |
| 202 | Notes |
| 203 | ----- |
| 204 | On NT, DOS systems the returned status is correct for external commands. |
| 205 | Wild cards will not work for non-posix systems or when use_shell=0. |
| 206 | |
| 207 | """ |
| 208 | # 2019-01-30, 1.17 |
| 209 | warnings.warn('exec_command is deprecated since NumPy v1.17, use ' |
| 210 | 'subprocess.Popen instead', DeprecationWarning, stacklevel=1) |
| 211 | log.debug('exec_command(%r,%s)' % (command, |
| 212 | ','.join(['%s=%r'%kv for kv in env.items()]))) |
| 213 | |
| 214 | if use_tee is None: |
| 215 | use_tee = os.name=='posix' |
| 216 | if use_shell is None: |
| 217 | use_shell = os.name=='posix' |
| 218 | execute_in = os.path.abspath(execute_in) |
| 219 | oldcwd = os.path.abspath(os.getcwd()) |
| 220 | |
| 221 | if __name__[-12:] == 'exec_command': |
| 222 | exec_dir = os.path.dirname(os.path.abspath(__file__)) |
| 223 | elif os.path.isfile('exec_command.py'): |
| 224 | exec_dir = os.path.abspath('.') |
| 225 | else: |
| 226 | exec_dir = os.path.abspath(sys.argv[0]) |
| 227 | if os.path.isfile(exec_dir): |
| 228 | exec_dir = os.path.dirname(exec_dir) |
| 229 | |
| 230 | if oldcwd!=execute_in: |
| 231 | os.chdir(execute_in) |
| 232 | log.debug('New cwd: %s' % execute_in) |
| 233 | else: |
| 234 | log.debug('Retaining cwd: %s' % oldcwd) |
nothing calls this directly
no test coverage detected