编辑包含工作脚本
以下是基于用户答案的工作脚本
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()
userLoggedOn = out.split('\n')[1].strip()
print userLoggedOn, "is output"
我正在尝试格式化子进程的输出
Python脚本
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()
userLoggedOn = out.strip('Users logged on locally:')
print userLoggedOn, "is output"
提供以下输出
Users logged on locally:
DOMAIN\user
is output
如何剥离"本地登录的用户:"所以输出
DOMAIN\user is output