Ticket #153: Parent.au3

File Parent.au3, 1.2 KB (added by Valik, 14 years ago)
Line 
1#include <Constants.au3>
2
3Global $g_nExitCode = Main()
4Exit $g_nExitCode
5
6Func Main()
7        If $CmdLine[0] Then
8                Call($CmdLine[1])
9                If @error Then MsgBox(4096 + 16, "Error", "Invalid function")
10        Else
11                Master()
12        EndIf
13EndFunc ; Main()
14
15Func Master()
16        Local $pid = RunSelf("Parent", $STDIN_CHILD + $STDERR_CHILD + $STDOUT_CHILD)
17        ProcessWaitClose($pid)
18        MsgBox(4096, "", "From Parent:" & @CRLF & StdoutRead($pid))
19EndFunc ; Master()
20
21Func Parent()
22        ConsoleWrite("Parent!!!" & @CRLF)
23        Local Const $sChildExe = @ScriptDir & "\Child.exe"
24        If Not FileExists($sChildExe) Then Return MsgBox(4096 + 16, "Error", "Unable to find child executable")
25        Local $pid = Run($sChildExe, @WorkingDir, @SW_SHOWNORMAL, $STDIN_CHILD + $STDERR_MERGED)
26        ProcessWaitClose($pid)
27        Local $s = StdoutRead($pid)
28        MsgBox(4096, "", "From Child:" & @CRLF & $s)
29        ConsoleWrite($s)
30EndFunc ; Parent()
31
32Func RunSelf($sCmdLine, $nStdio = 0, $sWorkingDir = @WorkingDir, $nShow = @SW_SHOWNORMAL)
33        Local $sCmd
34        If @Compiled Then
35                $sCmd = @AutoItExe & " " & $sCmdLine
36        Else
37                $sCmd = @AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" ' & $sCmdLine
38        EndIf
39        Return Run($sCmd, $sWorkingDir, $nShow, $nStdio)
40EndFunc ; RunSelf()