Sign in to follow this  
Followers 0
jmoreira

Get remote SESSIONAME to StdoutRead, for logoff purpose

3 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  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

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

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0