1
votes

I want to open a process as a different user for which I researched a lot and found that no cmd or python script can help me to achieve my goal, but the Start-Process command of powershell can. The issue currently I am facing is while passing arguments to my python script via Start-Process in powershell. I tried using -ArgumentList but that doesn't helped me as I have to pass arguments as a dict to python. Below is my script which I was running:
Start-Process python.exe "E:\test_installer\src\client\sql_server\sql_agent_ process.py" {"request_type": "backup", "client_id": 15, "request_id": 39431, "bkpset_id": 18, "ppid": 33796, "fromsource": "True"}
Can someone please help me here? Thanks in advance.

1
I'm not familiar with Python but If the json dictionary count as one argument, you could do : Start-Process -FilePath python.exe -ArgumentList "E:\test_installer\src\client\sql_server\sql_agent_process.py", '{"request_type": "backup", "client_id": 15, "request_id": 39431, "bkpset_id": 18, "ppid": 33796, "fromsource": "True"}' - Sage Pourpre

1 Answers

1
votes

You can try to pass the argument to the script as a string then use the ast.literal_eval to convert it back to dictionary.

In your python script use the sys.argv to get the command line argument.

It should look something like this:

import sys
import ast
command_line_args = ast.literal_eval(sys.argv[1])

While the powershell command is:

Start-Process python.exe "E:\test_installer\src\client\sql_server\sql_agent_
process.py" "{\"request_type\": \"backup\", \"client_id\": 15, \"request_id\": 39431, \"bkpset_id\": 18, \"ppid\": 33796, \"fromsource\": True}"