1

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"}' Commented Jan 6, 2020 at 6:34

1 Answer 1

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}"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Amiram, it worked fine. I added sys.argv to python and used your ps command to access. Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.