I have Python code for detecting input parameter - How to do similar in
Powershell
I have snippit of Python code that AUTOMATICALLY detects one of many
parameters that an external program is sending.
In this case, the parameter name is 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)
How to do this in powershell, i.e. an external program that I have no
control over send in many variables, i.e. sent-data, sender-name,
sender-up, etc. How do I make my program detect only sent-data, just like
this Python code did.
No comments:
Post a Comment