简体   繁体   English

在python中清除sys.argv

[英]Clear sys.argv in python

When user specify a password in MySQL cli, aka -pXXXXXX , the password parameter is replaced to -p****** in argv array.当用户在 MySQL cli 中指定密码时,又名-pXXXXXX ,密码参数将替换为 argv 数组中的-p******

So when someone check the process list with ps , they can't see the password.所以当有人用ps检查进程列表时,他们看不到密码。

How can I do the same in Python?我如何在 Python 中做同样的事情? This doesn't work obviously这显然不起作用

for arg in sys.argv[1:]:
    arg = ""

sys.argv = [sys.argv[0]]

works and is more efficient and elegant than deleting all but the first element.有效并且比删除除第一个元素之外的所有元素更有效和优雅。 I can't confirm this would overwrite or erase previous value of sys.argv in memory though.我无法确认这会覆盖或擦除内存中 sys.argv 的先前值。

You can make a wrapper that accepts a password and other arguments.您可以制作一个接受密码和其他参数的包装器。 It will then spawn a child, pass it the password in the way that's not visible in command line, eg.然后它会产生一个孩子,以命令行中不可见的方式将密码传递给它,例如。 with multiprocessing , and kill itself.multiprocessing ,并杀死自己。 For killing processes while keeping their children alive look here .要在保持孩子存活的同时杀死进程,请看这里

我没有找到方法,所以我转向令牌的环境变量(并在获取后取消设置以防止泄漏到子进程)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM