Jump to content

Recommended Posts

Posted

Hi,

I'm trying to get remote SESSIONNAME to StdoutRead, for logoff purpose using qwinsta | findstr and cut (from http://unxutils.sourceforge.net/). It works in command prompt but can't get it in script.

Help is needed, anyone have a clue?

(code below)

#include <Constants.au3>

Local $server="server", $domain="domain", $user="user", $password="passwd"

$var = 'qwinsta.exe '&$user&' /server:'&$server&' | findstr rdp | cut -c2-11'
; result should be: rdp-tcp#0 

MsgBox(0, "STDOUT read:", _getDOSOutput($var))
; but nothing appears in MsgBox

Runwait(@ComSpec & " /c " & 'logoff '&_getDOSOutput($var)&' /SERVER:'&$server&'', "", @SW_HIDE)

Func _getDOSOutput($command)
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
            $text &= StdoutRead($Pid, False, False)
            If @error Then ExitLoop
            Sleep(10)
    WEnd
    Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput
Posted (edited)

Hi jmoreira

if there is an error in the command in $var in line 5, then you do not see the output because you do not fetch the StdErr

in line 14 try adding +8  ($STDERR_MERGED) to capture even the error messages with StdoutRead()

Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4 + 8)
Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

Hi Universalist,

There is no error in $var, but after adding +8  ($STDERR_MERGED) i get in StdoutRead():

'cut' is not recognized as an internal or external command, operable program or batch file. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...