2

这是Invoke pstools in Python script的后续

当我打开命令提示符并执行

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

我明白了

DOMAIN\user

但是当我执行脚本时

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"

我明白了

Error opening HKEY_USERS for \10.10.10.10
is output

如何让子进程将 IP 地址读取为 \10.10.10.10 而不是 \10.10.10.10

顺便说一句,我尝试添加第三个反斜杠

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

输出是

Error opening HKEY_USERS for .0.139.40
is output
4

1 回答 1

1

正如 lejlot 的评论所建议的,你必须使用 "\\" 因为 "\" 是 python 中的转义字符。

于 2014-05-17T10:52:16.283 回答