jmoreira Posted November 25, 2013 Share Posted November 25, 2013 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 Link to comment Share on other sites More sharing options...
Gianni Posted November 25, 2013 Share Posted November 25, 2013 (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 November 25, 2013 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jmoreira Posted November 29, 2013 Author Share Posted November 29, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now