In a bit of a bind here. I am attempting to dump a dictionary called DATA into a json file. I have a few keys in this dictionary, one of them being called options. I'm populating this dictionary with windows environment variables although that shouldn't matter too much. Here is my code:
TOOL = sys.argv[1]
TARGET = sys.argv[2]
HASH = sys.argv[3]
TESTCASE = sys.argv[4]
OPTIONS = sys.argv[5]
DATA = {'test': TOOL.replace("'", ""), 'target': TARGET.replace("'", ""),
'HASH': HASH.replace("'", ""),
'options': OPTIONS.replace("'", ""),
'TESTCASE_EXECUTIONRECORD_NAME': TESTCASE.replace("'", "")}
def write_to_json():
"""Serialize cli args and tool options in json format.
Write stream to json file.
"""
with open(r'C:\Users\tommy12\PycharmProjects\SomethingNew\envs.json',
'w') as json_file:
json.dump(DATA, json_file)
write_to_json()
I'll run the program with the following command
python jsonprogram.py %TOOL% %TARGET% 434999 test %OPTIONS%
Here are the environment variables tool = 'nmap', target = 'scanme.nmap.org' and options = '-cA "-sS -p1-1000 "'
Everything will format correctly expect for the options. For my json option value, I will have just -cA. I've tried using quotes in different places but nothing has helped. Does anyone know how to keep options in tact? I need the options format to be -cA "-sS -p-1000 " with the trailing space after 1000. The double quotes are necessary as well.