Jump to content

Child process console debug to parent's console.


Recommended Posts

I know there are a few UDFs where the child can output the parent's console, but I am wondering how I could use the

Parent:

_DebugSetup ("Debug Window", false, 2)
_DebugOut("Hello, I am the parent");
LaunchChild()

Child:

_DebugSetup ("Debug Window", false, 2)
_DebugOut("Hello, I am the child");

Console Reads:

Hello, I am the parent

How would I setup the debug functions to correctly redirect the debug message to the parents console?

Edit: Added Example

I made a quick example

#include <Debug.au3>


_DebugSetup ("Debug Window", false, 1)
CheckIfChild()

_DebugOut("Hello, I am the parent");

EnvSet("ChildProc", "0x" & Hex(StringToBinary("Child")))

$iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir)


Func Child()
    _DebugOut("Hello, I am the child");
EndFunc


Func CheckIfChild()
    $sCmd = EnvGet("ChildProc")
    If StringLeft($sCmd, 2) = "0x" Then
        $sCmd = BinaryToString($sCmd)
        Call($sCmd)

        If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd)
        Exit
    EndIf
EndFunc

With _DebugSetup ("Debug Window", false, 2), Console reads:

Hello, I am the parent

With _DebugSetup ("Debug Window", false, 1), Debug Window reads:

Hello, I am the parent
Hello, I am the child

It's my suggestion that the debug setup should automatically output to the parent's console.

Edited by ParoXsitiC
Link to comment
Share on other sites

Post a short, complete, RUNNING script that demonstrates your issue. For example, what's in LaunchChild()?

I don't see how there is any parent/child relationship between your two instances of _Debug*.

:huh2:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Upon looking at the help topics on the Run function to make the demo, I ran into the solution.

Run ( "program" [, "workingdir" [, show_flag[, opt_flag ]]] )

opt_flag:

0x10 ($STDIO_INHERIT_PARENT) = Provide the child with the parent's STDIO streams. This flag can not be combined with any other STDIO flag. This flag is only useful when the parent is compiled as a Console application.

The following code will fix the problem:

Global Const $STDIO_INHERIT_PARENT = 0x10
$iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, default, $STDIO_INHERIT_PARENT )

Here it is fully:

#include <Debug.au3>
Global Const $STDIO_INHERIT_PARENT = 0x10

_DebugSetup ("Debug Window", false, 2)
CheckIfChild()

_DebugOut("Hello, I am the parent");

EnvSet("ChildProc", "0x" & Hex(StringToBinary("Child")))

$iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, default, $STDIO_INHERIT_PARENT )


Func Child()
    _DebugOut("Hello, I am the child");
EndFunc


Func CheckIfChild()
    $sCmd = EnvGet("ChildProc")
    If StringLeft($sCmd, 2) = "0x" Then
        $sCmd = BinaryToString($sCmd)
        Call($sCmd)

        If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd)
        Exit
    EndIf
EndFunc
Edited by ParoXsitiC
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...