Sign in to follow this  
Followers 0
nullschritt

IPC via stdinwrite() and consoleread()

6 posts in this topic

Hello I am attempting some IPC between two scripts, I have been able to get it to work this way in the past, but it's been a long while since I've coded that script.

Below is what I have so far, what it should do is write the current number to the stdin stream of the child process, and the child process should write to a file any data it receives.

However it seems the child process is not getting the messages.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
if not @Compiled then Exit
If $cmdlineraw = "/IPC" Then
    $buffer = ""
    While 1
        Sleep(10)
        _checkstdin()
    WEnd
EndIf
$IPC = run(@ScriptFullPath&" /IPC", @ScriptDir, @SW_HIDE)
$i = 0
while 1
    StdinWrite($IPC, $i)
    ConsoleWrite($I&@CRLF)
    $i += 1
    sleep(10)
WEnd
func _checkstdin()
;subprocess gets commands and sends to main
$buffer &= ConsoleRead()
if $buffer <> "" Then
FileWrite(@ScriptDir&'\log.txt', $buffer&@CRLF)
EndIf
$buffer = ""
EndFunc

(this must be compiled to work, obviously)

Share this post


Link to post
Share on other sites



Does it have to be StdinWrite and ConsoleRead? There are many IPC solutions available. One of the best seems to be Mailslot written by trancexx.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi nullschritt

in your script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
if not @Compiled then Exit
If $cmdlineraw = "/IPC" Then
    $buffer = ""
    While 1
        Sleep(10)
        _checkstdin()
    WEnd
EndIf
$IPC = run(@ScriptFullPath&" /IPC", @ScriptDir, @SW_HIDE)
$i = 0
while 1
    StdinWrite($IPC, $i)
    ConsoleWrite($I&@CRLF)
    $i += 1
    sleep(10)
WEnd
func _checkstdin()
;subprocess gets commands and sends to main
$buffer &= ConsoleRead()
if $buffer <> "" Then
; FileWrite(@ScriptDir&'\log.txt', $buffer&@CRLF)
    ConsoleWrite($buffer&@CRLF)
EndIf
$buffer = ""
ConsoleWrite(".")
EndFunc

it seems that

if you run the compiled script without the /IPC parameter then it works because it receives the numbers comming from the StdinWrite() Statement in line 24;

but if You run the compiled script with the /IPC parameter then the script just loops around (lines 16 -19) waiting incoming data that nobody is sending;

if you add line 37 you can see that the script is looping in vain

Bye

EDIT:

:huh2:
 Trying the script I saw that running it without the /IPC parameter I see through the numbers 0 to 9 without the dot, while 10 and above the number is preceded by a period. this "dot" should not be there :think:  where that "dot" come from?

EDIT 2:

also .... $STDIN_CHILD + $STDOUT_CHILD must be added to RUN() statement in line 21 ......

I give up ... :)

Edited by Pincopanco
1 person likes this

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 nullschritt

in your script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
if not @Compiled then Exit
If $cmdlineraw = "/IPC" Then
    $buffer = ""
    While 1
        Sleep(10)
        _checkstdin()
    WEnd
EndIf
$IPC = run(@ScriptFullPath&" /IPC", @ScriptDir, @SW_HIDE)
$i = 0
while 1
    StdinWrite($IPC, $i)
    ConsoleWrite($I&@CRLF)
    $i += 1
    sleep(10)
WEnd
func _checkstdin()
;subprocess gets commands and sends to main
$buffer &= ConsoleRead()
if $buffer <> "" Then
; FileWrite(@ScriptDir&'\log.txt', $buffer&@CRLF)
    ConsoleWrite($buffer&@CRLF)
EndIf
$buffer = ""
ConsoleWrite(".")
EndFunc

it seems that

if you run the compiled script without the /IPC parameter then it works because it receives the numbers comming from the StdinWrite() Statement in line 24;

but if You run the compiled script with the /IPC parameter then the script just loops around (lines 16 -19) waiting incoming data that nobody is sending;

if you add line 37 you can see that the script is looping in vain

Bye

EDIT:

:huh2:

 Trying the script I saw that running it without the /IPC parameter I see through the numbers 0 to 9 without the dot, while 10 and above the number is preceded by a period. this "dot" should not be there :think:  where that "dot" come from?

EDIT 2:

also .... $STDIN_CHILD + $STDOUT_CHILD must be added to RUN() statement in line 21 ......

I give up ... :)

It seems adding $STDIN_CHILD to the run command works, so the IPC is now working in one direction, now I've just got see if I can get it to work both ways ($STDIN_CHILD + $STDOUT_CHILD), I haven't tried this in my code yet, but I will report back shortly when I have, although my thoughts abotu it working are doubtful, as it would seem that the above flags are requesting two different handles.

Share this post


Link to post
Share on other sites

Fantastic, it works both ways with these flags.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
if not @Compiled then Exit
If $cmdlineraw = "/IPC" Then
    $buffer = ""
    While 1
        Sleep(7)
        _checkstdin()
    WEnd
EndIf
$IPC = run(@ScriptFullPath&" /IPC", @ScriptDir, @SW_HIDE, 0x1 + 0x2)
$i = 0
while 1
    StdinWrite($IPC, $i)
    ConsoleWrite(StdoutRead($IPC))
    $i += 1
    sleep(10)
WEnd
func _checkstdin()
;subprocess gets commands and sends to main
$buffer &= ConsoleRead()
if $buffer <> "" Then
FileWrite(@ScriptDir&'\log.txt', $buffer&@CRLF)
ConsoleWrite($buffer&@CRLF)
EndIf
$buffer = ""
EndFunc

As you can see it sends text to the child, then the child sends it back to the main process, thanks for your help!

Share this post


Link to post
Share on other sites

hi nullschritt

now I see better the whole logic,

the compiled script must be run without the /IPC parameter so this script launches another instance of himself, but this time with the /IPC parameter. Now 2 istances are running, so the first instance sends the numbers to the second (in the while-whend lines 23 -28), and the second instance receives the numbers and sends them back to the first by the  _checkstdin() subroutine.

well, I'm glad you've solved by adding
the $STDIN_CHILD + $STDOUT_CHILD flags

Bye


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

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