Python脚本不执行sysinternals命令 [英] Python script not executing sysinternals command

查看:36
本文介绍了Python脚本不执行sysinternals命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 Python 脚本中调用 pstools

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

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

我明白

域\用户

但是当我执行脚本时

import sys, subprocess, socket, string导入 wmi、win32api、win32conpst = subprocess.Popen(["D:\pstools\psloggedon.exe", "-l", "-x", "\\10.10.10.10"],标准输出 = subprocess.PIPE,stderr = subprocess.PIPE)出,错误 = pst.communicate()打印出来,是输出"

我明白

为 \10.10.10.10 打开 HKEY_USERS 时出错是输出

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

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

pst = subprocess.Popen([D:\pstools\psloggedon.exe"、-l"、-x"、\\10.10.10.10"]、标准输出 = subprocess.PIPE,stderr = subprocess.PIPE)

输出是

打开 .0.139.40 的 HKEY_USERS 时出错是输出

解决方案

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

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

解决方案

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

这篇关于Python脚本不执行sysinternals命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆