![](/img/trans.png)
[英]python subprocess doesn't seem to work properly when there's no console attached
[英]The If else statement for Python's subprocess doesn't seem to work
我創建了一個簡單的腳本來定位本地機器上的用戶。 盡管在輸入框中輸入了任何字符,但答案保持不變。 我很感激任何幫助。
#!/usr/bin/python
import subprocess
user = input("Enter username : ")
result = subprocess.getoutput("getent passwd" + user)
if result:
print(("found "+user+" user in this system."))
else:
print((""+user+" is not found..."))
這是因為在連接中,它應該是一個分隔database
和key
的空間:
#!/usr/bin/python
import subprocess
user = input("Enter username : ")
result = subprocess.getoutput("getent passwd " + user) #added space after 'passwd'
if result:
print(("found "+user+" user in this system."))
else:
print((""+user+" is not found..."))
此外,雙括號是不必要的。
#!/usr/bin/python
import subprocess
user = input("Enter username : ")
result = subprocess.getoutput("getent passwd " + user) #added space after 'passwd'
if result:
print("found "+user+" user in this system.")
else:
print(user+" is not found...")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.