(command, *args)
| 422 | |
| 423 | |
| 424 | def _get_command_stdout(command, *args): |
| 425 | import io, os, shutil, subprocess |
| 426 | |
| 427 | try: |
| 428 | path_dirs = os.environ.get('PATH', os.defpath).split(os.pathsep) |
| 429 | path_dirs.extend(['/sbin', '/usr/sbin']) |
| 430 | executable = shutil.which(command, path=os.pathsep.join(path_dirs)) |
| 431 | if executable is None: |
| 432 | return None |
| 433 | # LC_ALL=C to ensure English output, stderr=DEVNULL to prevent output |
| 434 | # on stderr (Note: we don't have an example where the words we search |
| 435 | # for are actually localized, but in theory some system could do so.) |
| 436 | env = dict(os.environ) |
| 437 | env['LC_ALL'] = 'C' |
| 438 | # Empty strings will be quoted by popen so we should just omit it |
| 439 | if args != ('',): |
| 440 | command = (executable, *args) |
| 441 | else: |
| 442 | command = (executable,) |
| 443 | proc = subprocess.Popen(command, |
| 444 | stdout=subprocess.PIPE, |
| 445 | stderr=subprocess.DEVNULL, |
| 446 | env=env) |
| 447 | if not proc: |
| 448 | return None |
| 449 | stdout, stderr = proc.communicate() |
| 450 | return io.BytesIO(stdout) |
| 451 | except (OSError, subprocess.SubprocessError): |
| 452 | return None |
| 453 | |
| 454 | |
| 455 | # For MAC (a.k.a. IEEE 802, or EUI-48) addresses, the second least significant |
no test coverage detected
searching dependent graphs…