我有自动检测外部程序发送的许多参数之一的 Python 代码片段。
在这种情况下,参数名称为 date-sent
__name__="__main__"
import sys, os, traceback
import commands
# Switch this to 0 when in production mode.
debugMode = 1
def main(args):
try:
attributeMap = parseInput(args)
dateSent = attributeMap["date-sent"]
print "Script-attribute=script value"
return
except:
error()
print "something went wrong!"
return "something went wrong!"
def parseInput(args):
attributeMap = {}
delimiter = "="
for item in args:
if delimiter in item:
tuple = item.split(delimiter)
attributeMap[tuple[0]] = tuple[1]
return attributeMap
def error():
# "SCRIPT PROCESSING ERROR"
if(debugMode):
traceback.print_exc(file=sys.stdout)
return ""
#-----------------------------------------------------------------
# DOS-style shells (for DOS, NT, OS/2):
#-----------------------------------------------------------------
def getstatusoutput(cmd):
""" Return (status, output) of executing cmd in a
shell."""
pipe = os.popen(cmd + ' 2>&1', 'r')
text = pipe.read()
sts = pipe.close()
if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1]
return sts, text
#-----------------------------------------------------------------
# Entry Point
#-----------------------------------------------------------------
if __name__ == "__main__":
if(len(sys.argv) == 0):
error()
else:
main(sys.argv)
如何在 powershell 中执行此操作,即我无法控制在许多变量中发送的外部程序,即发送数据、发件人名称、发件人等。如何让我的程序仅检测发送数据就像这个 Python 代码一样。