Python script not executing sysinternals command

 ̄綄美尐妖づ 提交于 2020-01-21 14:40:08

问题


This is a follow-up from Invoke pstools in Python script

When I open a command prompt and execute

D:\pstools\psloggedon.exe -l -x \\10.10.10.10

I get

DOMAIN\user

But when I execute the script

import sys, subprocess, socket, string
import wmi, win32api, win32con



pst = subprocess.Popen(
        ["D:\pstools\psloggedon.exe", "-l", "-x", "\\10.10.10.10"],
        stdout = subprocess.PIPE,
        stderr = subprocess.PIPE
    )

out, error = pst.communicate()


print out, "is output"

I get

Error opening HKEY_USERS for \10.10.10.10
is output

How do I get the subprocess to read the IP address as \10.10.10.10 instead of \10.10.10.10

By the way, I tried to add third backslash

pst = subprocess.Popen(
        ["D:\pstools\psloggedon.exe", "-l", "-x", "\\\10.10.10.10"],
        stdout = subprocess.PIPE,
        stderr = subprocess.PIPE
    )

And the output is

Error opening HKEY_USERS for .0.139.40
is output

回答1:


As suggested by lejlot's comment you have to use "\\" because "\" is an escape character in python.



来源:https://stackoverflow.com/questions/23686333/python-script-not-executing-sysinternals-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!