[英]How to pass python arguments via start-process powershell
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.我想以不同的用户身份打开一个进程,我对其进行了大量研究,发现没有 cmd 或 python 脚本可以帮助我实现我的目标,但是 powershell 的 Start-Process 命令可以。 The issue currently I am facing is while passing arguments to my python script via Start-Process in powershell.
我目前面临的问题是通过 powershell 中的 Start-Process 将参数传递给我的 python 脚本。 I tried using -ArgumentList but that doesn't helped me as I have to pass arguments as a dict to python.
我尝试使用 -ArgumentList 但这对我没有帮助,因为我必须将参数作为 dict 传递给 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.
提前致谢。
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.您可以尝试将参数作为
string
传递给脚本,然后使用ast.literal_eval将其转换回字典。
In your python script use the sys.argv
to get the command line argument.在您的 python 脚本中,使用
sys.argv
来获取命令行参数。
It should look something like this:它应该是这样的:
import sys
import ast
command_line_args = ast.literal_eval(sys.argv[1])
While the powershell
command is:而
powershell
命令是:
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}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.