(command, *args)
| 358 | |
| 359 | |
| 360 | def _get_command_stdout(command, *args): |
| 361 | import io, os, shutil, subprocess |
| 362 | |
| 363 | try: |
| 364 | path_dirs = os.environ.get('PATH', os.defpath).split(os.pathsep) |
| 365 | path_dirs.extend(['/sbin', '/usr/sbin']) |
| 366 | executable = shutil.which(command, path=os.pathsep.join(path_dirs)) |
| 367 | if executable is None: |
| 368 | return None |
| 369 | # LC_ALL=C to ensure English output, stderr=DEVNULL to prevent output |
| 370 | # on stderr (Note: we don't have an example where the words we search |
| 371 | # for are actually localized, but in theory some system could do so.) |
| 372 | env = dict(os.environ) |
| 373 | env['LC_ALL'] = 'C' |
| 374 | # Empty strings will be quoted by popen so we should just ommit it |
| 375 | if args != ('',): |
| 376 | command = (executable, *args) |
| 377 | else: |
| 378 | command = (executable,) |
| 379 | proc = subprocess.Popen(command, |
| 380 | stdout=subprocess.PIPE, |
| 381 | stderr=subprocess.DEVNULL, |
| 382 | env=env) |
| 383 | if not proc: |
| 384 | return None |
| 385 | stdout, stderr = proc.communicate() |
| 386 | return io.BytesIO(stdout) |
| 387 | except (OSError, subprocess.SubprocessError): |
| 388 | return None |
| 389 | |
| 390 | |
| 391 | # For MAC (a.k.a. IEEE 802, or EUI-48) addresses, the second least significant |
no test coverage detected