本文整理匯總了Python中subprocess.mswindows方法的典型用法代碼示例。如果您正苦於以下問題:Python subprocess.mswindows方法的具體用法?Python subprocess.mswindows怎麽用?Python subprocess.mswindows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類subprocess
的用法示例。
在下文中一共展示了subprocess.mswindows方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: stdout_encode
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import mswindows [as 別名]
def stdout_encode(data):
try:
data = data or ""
# Reference: http://bugs.python.org/issue1602
if mswindows:
output = data.encode(sys.stdout.encoding, "replace")
if '?' in output and '?' not in data:
warn = "cannot properly display Unicode characters "
warn += "inside Windows OS command prompt "
warn += "(http://bugs.python.org/issue1602). All "
warn += "unhandled occurances will result in "
warn += "replacement with '?' character. Please, find "
warn += "proper character representation inside "
warn += "corresponding output files. "
single_time_warn_message(warn)
ret = output
else:
ret = data.encode(sys.stdout.encoding)
except Exception as e:
ret = data.encode(UNICODE_ENCODING) if isinstance(data, unicode) else data
return ret
示例2: beep
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import mswindows [as 別名]
def beep():
try:
if subprocess.mswindows:
_win_wav_play(BEEP_WAV_FILENAME)
elif sys.platform == "darwin":
_mac_beep()
elif sys.platform == "linux2":
_linux_wav_play(BEEP_WAV_FILENAME)
else:
_speaker_beep()
except:
_speaker_beep()
示例3: check_sudo
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import mswindows [as 別名]
def check_sudo():
retval = None
if not subprocess.mswindows:
if getattr(os, "geteuid"):
retval = os.geteuid() == 0
else:
import ctypes
retval = ctypes.windll.shell32.IsUserAnAdmin()
return retval
示例4: colorize
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import mswindows [as 別名]
def colorize(message):
if not subprocess.mswindows and sys.stdout.isatty():
message = re.sub(r"\[(.)\]", lambda match: "[%s%s\033[00;49m]" % (LEVEL_COLORS[match.group(1)], match.group(1)), message)
message = message.replace("@sqlmap", "\033[00;96m@sqlmap\033[00;49m")
message = message.replace(NAME, "\033[00;93m%s\033[00;49m" % NAME)
return message
示例5: main
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import mswindows [as 別名]
def main():
print (r" ")
print (r" \ \ / / ")
print (r"__ _____ __\ \ / /__ _ __ ")
print (r"\ \/ / _ \/ __\ \/ / _ \ '__|")
print (r" > < (_) \__ \\ / __/ | ")
print (r"/_/\_\___/|___/ \/ \___|_| ")
print (r" ")
IS_WIN = subprocess.mswindows
_ = os.path.normpath(sys.argv[0])
usage = "%s%s <options>" % ("python" if not IS_WIN else "", \
"\"%s\"" % _ if " " in _ else _)
print ("Version: {0}".format(__version__))
parser = OptionParser(usage=usage)
try:
parser.add_option("--hh", dest="help",
action="store_true",
help="Show help message and exit")
parser.add_option("-i", dest="ip",
help="Single IP scan mode (eg:192.168.1.11)")
parser.add_option("-p", dest="ips",
help="Batch IP scan mode (eg:192.168.1.10/20)")
parser.add_option("-o", dest="output",
help="Save results to a file",
default = False)
parser.add_option("--timeout", dest="timeout", type="int",
help="Seconds to wait before timeout connection "
"(default 2)", default = 2)
args = []
for arg in sys.argv:
args.append(arg)
(args, _) = parser.parse_args(args)
if not any((args.ip, args.ips)):
errMsg = "use -h for help"
parser.error(errMsg)
for i in xrange(len(sys.argv)):
try:
if sys.argv[i] == '-i':
reip = re.compile(r'(?<![\.\d])(?:\d{1,3}\.){3}\d{1,3}(?![\.\d])')
for ip in reip.findall(args.ip):ip
xosVer(ip, args.timeout, args.output)
elif sys.argv[i] == '-p':
reip = re.compile(r'(?<![\.\d])(?:\d{1,3}\.){3}\d{1,3}(?![\.\d])/\d{1,3}')
for ip in reip.findall(args.ips):ip
ip = ip.split('/')
exIp = ip[0][:ip[0].rfind('.') + 1]
sIp = int(ip[0][ip[0].rfind('.') + 1:], 10)
eIp = int(ip[1], 10) + 1
for i in xrange(sIp, eIp):
xosVer(exIp + str(i), args.timeout, args.output)
except Exception, e:
print ("\r\noption %s invalid value: %s" % (sys.argv[i], sys.argv[i + 1]))
print ("\r\nuse -h for help")
except (OptionError,TypeError), e:
parser.error(e)
示例6: read_config
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import mswindows [as 別名]
def read_config(config_file):
global config
if not os.path.isfile(config_file):
exit("[!] missing configuration file '%s'" % config_file)
config.clear()
try:
array = None
content = open(config_file, "rb").read()
for line in content.split("\n"):
line = re.sub(r"#.+", "", line)
if not line.strip():
continue
if line.count(' ') == 0:
array = line.upper()
config[array] = []
continue
if array and line.startswith(' '):
config[array].append(line.strip())
continue
else:
array = None
try:
name, value = line.strip().split(' ', 1)
except ValueError:
name = line.strip()
value = ""
finally:
name = name.upper()
value = value.strip("'\"")
if name.startswith("USE_"):
value = value.lower() in ("1", "true")
elif value.isdigit():
value = int(value)
else:
for match in re.finditer(r"\$([A-Z0-9_]+)", value):
if match.group(1) in globals():
value = value.replace(match.group(0), globals()[match.group(1)])
else:
value = value.replace(match.group(0), os.environ.get(match.group(1), match.group(0)))
if subprocess.mswindows and "://" not in value:
value = value.replace("/", "\\")
config[name] = value
except (IOError, OSError):
pass
for option in ("MONITOR_INTERFACE",):
if not option in config:
exit("[!] missing mandatory option '%s' in configuration file '%s'" % (option, config_file))