EmilyLove Posted April 17, 2020 Share Posted April 17, 2020 (edited) So I am trying to make a GUI for a console application. I need to be able to both read and write data to and from the console application's stream. Problem is, if I try to set the Run opt flag as BitOR($STDIN_CHILD, $STDOUT_CHILD), then I can't read the stream but I can write. I've also tried running as admin, it doesn't seem to help. There is no error reported, it just continues silently. I think this is a bug? expandcollapse popup#include <Array.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $iPID_NetCat = Null DirCreate(@TempDir & "\BetaLeaf Software\NetCat Tool\") If @OSArch = "X64" Then Global $sEXE_FileName = "nc64.exe" FileInstall("nc64.exe", @TempDir & "\BetaLeaf Software\NetCat Tool\nc64.exe") Else Global $sEXE_FileName = "nc.exe" FileInstall("nc.exe", @TempDir & "\BetaLeaf Software\NetCat Tool\nc.exe") EndIf #Region ### START Koda GUI section ### Form= $Form = GUICreate("NetCat Tool", 364, 254, 192, 124) $Label_SwitchConnectionSettings = GUICtrlCreateGroup("NetCat Connection Settings", 4, 0, 185, 100, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER)) $label_IPAddress = GUICtrlCreateLabel("IP Address", 8, 21, 55, 17, $SS_CENTER) $input_IPAddress = GUICtrlCreateInput("192.168.86.25", 80, 19, 100, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetLimit($input_IPAddress, 15) GUICtrlSetTip($input_IPAddress, "Example: 192.168.0.21") $label_Port = GUICtrlCreateLabel("Port", 8, 48, 23, 17, $SS_CENTER) $input_Port = GUICtrlCreateInput("", 80, 45, 100, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetLimit($input_Port, 5) GUICtrlSetTip($input_Port, "A port between 1-65535") $Label_ConnectionStatus = GUICtrlCreateLabel("Connection Status: Not Connected", 12, 73, 169, 17) GUICtrlSetColor($Label_ConnectionStatus, 0xFF0000) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### AdlibRegister("_AutoConnect", 250) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _AutoConnect() If $iPID_NetCat = Null Then ConsoleWrite("Starting..." & @CRLF) $iPID_NetCat = Run($sEXE_FileName & " " & GUICtrlRead($input_IPAddress) & " " & GUICtrlRead($input_Port), @TempDir & "\BetaLeaf Software\NetCat Tool\", @SW_HIDE, BitOR($STDIN_CHILD, $STDOUT_CHILD)) GUICtrlSetData($Label_ConnectionStatus, "Connection Status: Connecting...") GUICtrlSetColor($Label_ConnectionStatus, 0x0000ff) $timer = TimerInit() ConsoleWrite("Connecting..." & @CRLF) Do Sleep(1000) Local $vData = StdoutRead($iPID_NetCat) If @error Then ConsoleWrite("[ERROR]" & @error & "," & @extended & @CRLF) If @extended Then ConsoleWrite("[INFO]" & @extended & @CRLF) ConsoleWrite("[UPDATE]" & @CRLF & $vData & @CRLF) If StringInStr($vData, "Welcome to netcat!") Then ExitLoop Until TimerDiff($timer) > 16000 If ProcessExists($sEXE_FileName) Then GUICtrlSetData($Label_ConnectionStatus, "Connection Status: Connected!") GUICtrlSetColor($Label_ConnectionStatus, 0x00ff00) EndIf Else If Not ProcessExists($sEXE_FileName) Then ConsoleWrite("Lost connection!" & @CRLF) $iPID_NetCat = Null GUICtrlSetData($Label_ConnectionStatus, "Connection Status: Not Connected") GUICtrlSetColor($Label_ConnectionStatus, 0xff0000) EndIf EndIf EndFunc ;==>_AutoConnect Func _Parse() Sleep(250) Local $vData = StdoutRead($iPID_NetCat) ConsoleWrite("[UPDATE]" & @CRLF & $vData & @CRLF) EndFunc ;==>_Parse Edited April 18, 2020 by BetaLeaf Link to comment Share on other sites More sharing options...
Nine Posted April 17, 2020 Share Posted April 17, 2020 (edited) Might be because NetCat Tool doesn't write to the stream. It is not that impossible. Some programs that are console type, doesn't write on stream. To test your program use cmd.exe, instead of the tool. If that works and it doesn't with NetCat, you got your answer. Edited April 17, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Gianni Posted April 17, 2020 Share Posted April 17, 2020 (edited) Since OP says that when using streams individually they work regularly, I suppose the problem is in the general logic of the script rather than in nc.exe, and even less is a bug in the redirection of the RUN command. Where can I download sc.exe that you use? is this perhaps ?? (https://eternallybored.org/misc/netcat/) ?? Edited April 17, 2020 by Chimp 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...
EmilyLove Posted April 17, 2020 Author Share Posted April 17, 2020 6 hours ago, Chimp said: Where can I download sc.exe that you use? is this perhaps ?? (https://eternallybored.org/misc/netcat/) ?? Yes, thats it. Link to comment Share on other sites More sharing options...
EmilyLove Posted April 18, 2020 Author Share Posted April 18, 2020 12 hours ago, Nine said: Might be because NetCat Tool doesn't write to the stream. It is not that impossible. Some programs that are console type, doesn't write on stream. To test your program use cmd.exe, instead of the tool. If that works and it doesn't with NetCat, you got your answer. I tried the following and it doesn't seem to help: $iPID_NetCat = Run(@ComSpec & " /c " & $sEXE_FileName & " " & GUICtrlRead($input_IPAddress) & " " & GUICtrlRead($input_Port), @TempDir & "\BetaLeaf Software\NetCat Tool\", @SW_HIDE, BitOR($STDIN_CHILD, $STDOUT_CHILD)) And to be crystal clear, I'm not able to read the stream if both $STDIN_CHILD and either $STDOUT_CHILD, $STDERR_CHILD, or $STDERR_MERGED are used. If only one is used, then everything works as intended. Basically, if $STDIN_CHILD is used in addition to another opt flag, then $STDIN_CHILD doesn't work. It's like it can only do either a read or write stream at one time and it prioritizes the $STDOUT_CHILD stream Link to comment Share on other sites More sharing options...
EmilyLove Posted April 18, 2020 Author Share Posted April 18, 2020 Solved: Use NCat instead https://nmap.org/download.html Link to comment Share on other sites More sharing options...
BrewManNH Posted April 20, 2020 Share Posted April 20, 2020 With the Run command, don't use BitOr, just use + between the variable names, you need to add them together instead of Oring them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
TheXman Posted April 20, 2020 Share Posted April 20, 2020 (edited) 20 minutes ago, BrewManNH said: With the Run command, don't use BitOr, just use + between the variable names, you need to add them together instead of Oring them. The opt_flag values of the RUN command can be OR'ed without any issues because they all fall on bit boundaries. i.e. 1, 2, 4, 8, 16, and 65536 Edited April 20, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
EmilyLove Posted April 21, 2020 Author Share Posted April 21, 2020 Yea from my experiences it hasn't mattered. You can BitOR or simply add them. Thanks for the feedback though 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