Jump to content

Can't get the idea of StdinWrite


kcvinu
 Share

Recommended Posts

Hi all,

Last day i was tried some inter process communication code but not succeeded, as it is a big deal for me. Then i tried with ConsoleWriteError function. It worked for me. Here is my code. I am seeking suggestions to improve. 

But my doubt is that; I can't understand the idea of StdinWrite function completely. This is what i think. Please correct me if i am wrong.

1. Make a child program for collect and send the data.

2. Make a parent program and run the child within it and receive data from the child program.

So, i made the sample program with this scenario. But, when i looked StdinWrite function, it needs a process ID as a parameter. I thought that StdinWrite is used in the child program to send data to parent program. Am i right ?. 

My code

Child program for collecting and sending data.

Local $compName = @ComputerName
ConsoleWriteError($compName)
Exit

Parent program for receiving data

#include <AutoItConstants.au3>

Local $process = Run(@ScriptDir & "\stdWrite.exe","",Default, $STDERR_CHILD )
Local $Data
While 1
    $Data &= StderrRead($process)
    If $Data <> "" Then ExitLoop
WEnd
MsgBox(0, "Std Test Data", $Data)

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Never looked into this one myself.

Your parent program would use stdinwrite to send data to your child program.

For your child program to get information from its parent, it would use the ConoleRead function.

That is the opposite of what you have above.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Here is basic example.

Child.exe

Sleep(1000)

$var = ConsoleRead()

MsgBox(0,0,$var)

Parent.exe

#include <AutoItConstants.au3>

$pid = Run(@ScriptDir & "\Child.exe", @ScriptDir, @SW_SHOW, $STDIN_CHILD)

StdinWrite($pid, "Message from Parent.exe")

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Ok. Thank you @JohnOne. Now, its clear. But is it a good practice to use the method in my example ?

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

I'm uncertain how much of a buffer STDERR reserves so I'd keep that stream for reporting just that, errors.

I do not subscribe to what good and bad practices are outside of the notion of commenting your code if someone else is likely to use it, or keeping to standard practices defined by a group you might be working alongside.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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

×
×
  • Create New...