问题
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:
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}"
来源:https://stackoverflow.com/questions/59607551/how-to-pass-python-arguments-via-start-process-powershell