Jump to content

input/output


Recommended Posts

I am trying to write two applications that communicate with each other using StdoutWrite, read and the console. App1 runs App2 and one can send a string from App1 to App2. App2 retreives the string, does whatever it needs to and sends a string back to app1.

Problem is that if no message is sent from app1 to app2 and one retreives from the console, then i get a crash instead of an error which could be set or tested.

I already have a means to solve the problem by having app2 send a dummy message to the console in case it does not receve a message from app1. However, it would be much neater if an error could be tracked.

sorry, there's a couple of errors here, so i just edit them now. As for code tags, I was swithich to firefox while debugging some errors on a php site, and the button icons didn't show properly. I'll make a habbit of using them more often.

IVAN

below is the code for app1. This by the way is only an illustration rather than a fully fledged app!!

#include <Constants.au3>
#include <GuiConstants.au3>
$PidApp2 = Run("app2.exe", "", @SW_HIDE, 7) 


GUICreate("Communicator", 392, 323, (@DesktopWidth - 392) / 2, (@DesktopHeight - 323) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$EditRead = GUICtrlCreateEdit("", 20, 20, 350, 150)
$InputWrite = GUICtrlCreateInput("Write", 20, 210, 350, 30)
$ButtonReceive = GUICtrlCreateButton("Receive", 140, 270, 100, 30)
$ButtonSend = GUICtrlCreateButton("Send", 20, 270, 100, 30)
$ButtonExit = GUICtrlCreateButton("Exit", 260, 270, 110, 30)
$Receive = ""
$Send=""

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
     Case $msg = $ButtonReceive
         $Receive= StdoutRead($PidApp2)
         If @error Then Exit
         If $Receive<>"DoNothing" Then
         GUICtrlSetData ($EditRead, $Receive,1)
         EndIf
      Case $msg = $ButtonSend
         $Send = GUICtrlRead ( $InputWrite)
         $Sent=StdinWrite($PidApp2, $Send)
      Case $msg = $ButtonExit
         $Send = StdinWrite($PidApp2, "Close")
         ExitLoop
     EndSelect
WEnd
Exit

app2 reads from the console to $App1Msg. If $App1Msg is an empty string then it sends a dummy string to the console via ConsoleWrite("DoNothing").

Now, before I had this, autoit crashed if App1 read from the console a non existing string, that is before the dummy code was inserted:

If $App1Msg=="" Then
      ConsoleWrite("DoNothing")
  EndIf

This is the code to app2:

#include <Constants.au3>
While 1
   $App1Msg = ConsoleRead()
   If $App1Msg="close" Then
      MsgBox(0, "read item", $App1Msg)
      Exit
  ElseIf $App1Msg <> "" And $App1Msg<>"close" Then
      ConsoleWrite($App1Msg)
     ;MsgBox(0, "read item", $y)
  EndIf
   Sleep(250)
   If Not ProcessExists("app1.exe") Then
      Exit
  EndIf
  If $App1Msg=="" Then
      ConsoleWrite("DoNothing")
  EndIf
  $App1Msg=""
WEnd
Edited by ivan
Link to comment
Share on other sites

EDIT: I'll take a look at it when I get off work tonight. I'm sure there is an easy fix.

Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

I kind of solved the problem for getting 2 Autoit apps to talk to each other.

Below are the codes for App1.exe and App2.exe.

The crashing was solved with a dummy as follows:

A dummy string is sent from App1.exe to ensure that app2.exe has a text to read. App2.exe sends a message back to app1.exe. App1.exe does some text editing in case the message was sent from app2.exe.

I still need to work on how to retreive multiple lines of text through a loop, but i hope this can help others who might want to have two apps operating in parallel, with a means to coordinate what they do. I used to do this writing txt files in @tempdir.

regards,

IVAN

code for app1

#include <Constants.au3>
#include <GuiConstants.au3>
$PidApp2 = Run("app2.exe", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)


GUICreate("Communicator", 392, 323, (@DesktopWidth - 392) / 2, (@DesktopHeight - 323) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$EditRead = GUICtrlCreateEdit("", 20, 20, 350, 150)
$InputWrite = GUICtrlCreateInput("", 20, 210, 350, 30)
$ButtonReceive = GUICtrlCreateButton("Receive", 140, 270, 100, 30)
$ButtonSend = GUICtrlCreateButton("Send", 20, 270, 100, 30)
$ButtonExit = GUICtrlCreateButton("Exit", 260, 270, 110, 30)
$Receive = ""
$Send = ""

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $ButtonReceive
         $dummy = StdinWrite($PidApp2, 'dummy') 
         $Receive = StdoutRead($PidApp2)
         If @error Then Exit
         If StringInStr($Receive, 'DoNothing') Then
            $Receive = StringReplace($Receive, 'DoNothing', '')
         EndIf
         GUICtrlSetData($EditRead, $Receive, 1)
         
      Case $msg = $ButtonSend
         $Send = GUICtrlRead($InputWrite)
         GUICtrlSetData($InputWrite, '')
         If $Send <> "" Then
            $Sent = StdinWrite($PidApp2, $Send)
         ElseIf $Send == "" Then
            MsgBox(0, "error", "A string of text must be sent to app 2")
        EndIf
        
      Case $msg = $ButtonExit
         $Send = StdinWrite($PidApp2, "Close")
         ExitLoop
   EndSelect
WEnd
Exit

code for app2

#include <Constants.au3>
While 1
   $App1Msg = ConsoleRead() 
   
   If $App1Msg = "close" Then
      MsgBox(0, "read item", $App1Msg)
      Exit
   ElseIf $App1Msg <> "dummy" And $App1Msg <> "close" Then
      ConsoleWrite($App1Msg)
   EndIf
   Sleep(250)
   If Not ProcessExists("app1.exe") Then
      Exit
   EndIf
   If StringInStr($App1Msg, "dummy") Then 
      ConsoleWrite("DoNothing")
   EndIf
   $App1Msg = ""
WEnd
Link to comment
Share on other sites

Hi guys!

Since I had little feedback on this subject, I'll post the compiled and source in a zip folder. Run app1.exe, it will run app2. Send a string to app2 and app2 will throw it back to app1. uses i/o and console for communicating between the apps.

hope this can help others. for further info, read above threads.

IVAN

i_o_console.zip

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...