0

EDITED TO INCLUDE WORKING SCRIPT

Here is working script based on user's answers

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"




I am trying to format output from a subprocess

Python 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()

userLoggedOn = out.strip('Users logged on locally:')


print userLoggedOn, "is output"

Gives the following output

Users logged on locally:
        DOMAIN\user
is output

How do I strip out "Users logged on locally:" so that it outputs

DOMAIN\user is output
Glowie
  • 2,271
  • 21
  • 60
  • 104

0 Answers0