I am writing Python code to get the username of logged user from another computer in a local network. The request works separately both in the command line and in the powershell. However, when I try to enter a request through the subprocess in Python, an error occurs. Tell me what am I doing wrong?
import subprocess, sys
p = subprocess.Popen(["powershell.exe",
"query session /server:com190"],
stdout=sys.stdout)
p.communicate()
Result:
*query : The term 'query' is not recognized as the name of a cmdlet, function, s cript file, or operable program. Check the spelling of the name, or if a path w as included, verify that the path is correct and try again. At line:1 char:1
- query session /server:com190
- CategoryInfo : ObjectNotFound: (query:String) [], CommandNotFou ndException
- FullyQualifiedErrorId : CommandNotFoundException*
Commands like ipconfig and ping works perfect in the code.