Jump to content

Communication between scripts


Recommended Posts

Hi there,

I would like to run a Perl script from within my AutoIt script and get what the Perl returns. The simplest way is to make Perl write its output into the file and make AutoIt script read the file. Is there another maybe more elegant approach possible?

Thanks in advance for your help.

Warmly,Narciso

Link to comment
Share on other sites

try consoleread or stdoutread. all you should do is have the perl script 'print' out the necessary output to the screen.

consoleread or stderr, stdoutread should be able to read this output.

have a nice day.

Dimitri

Do you mean to say I would have to generate a black console window with Perl output and only then AutoIt would read the console? Doesn't seem very elegant for the user operating AutoIt program, does it?

Warmly,Narciso

Link to comment
Share on other sites

Well, no, the console doesn't have to be visible, it can be minimized or hidden. What are you looking for? If your Perl script includes:

print "Hello world!\n";

Then you would see it with StdOutRead(). This will probably be faster than file I/O, but if you don't like it, give us clue what you WOULD like. You want to write to shared memory? You want the Perl code to put data in a GUI control to be read by AutoIt? What?

:)

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

Well, no, the console doesn't have to be visible, it can be minimized or hidden. What are you looking for? If your Perl script includes:

print "Hello world!\n";

Then you would see it with StdOutRead(). This will probably be faster than file I/O, but if you don't like it, give us clue what you WOULD like. You want to write to shared memory? You want the Perl code to put data in a GUI control to be read by AutoIt? What?

:)

Well, I would like AutoIt to launch the Perl script scilently (with no visible console) and after Perl has finished its job I would like it to return the result like a string "Hello world", sorted array or whatever to the AutoIt script. Hope I have made myself clear this time :D

Warmly,Narciso

Link to comment
Share on other sites

Well, I would like AutoIt to launch the Perl script scilently (with no visible console) and after Perl has finished its job I would like it to return the result like a string "Hello world", sorted array or whatever to the AutoIt script. Hope I have made myself clear this time :)

If the Perl script just does print with the results, you can read them with StdOutRead(). Another possibility is to have the Perl script exit with a return code (DOS %ERRORLEVEL%), but it would have to be a single numeric integer (which could be the BitOr of several flags, however).

Example using StdOutRead():

$ExtCmd = "Perl.exe MyPerl.pl"
$StdOut = ""
$StdErr = ""
$Pid = Run(@ComSpec & " /c " & $ExtCmd, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD + STDERR_CHILD)
While 1
    $StdOut &= StdoutRead($Pid)
    $StdErr &= StdErrRead($Pid)
    If @error Then ExitLoop
WEnd

MsgBox(64, "Result", "StdOut was: " & $StdOut & @CRLF & "ErrOut was: " & $StdErr)

:D

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

Example using StdOutRead():

$ExtCmd = "Perl.exe MyPerl.pl"
$StdOut = ""
$StdErr = ""
$Pid = Run(@ComSpec & " /c " & $ExtCmd, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD + STDERR_CHILD)
While 1
    $StdOut &= StdoutRead($Pid)
    $StdErr &= StdErrRead($Pid)
    If @error Then ExitLoop
WEnd

MsgBox(64, "Result", "StdOut was: " & $StdOut & @CRLF & "ErrOut was: " & $StdErr)oÝ÷ Ûú®¢×¡ë'ßÛlyé­£
+¦ëmx-+oÝ÷ Ú«¨µá1jjezë"
Þ¶êçr^jëh×6$ExtCmd = "Perl.exe MyPerl.pl"
$RET = RunWait(@ComSpec & " /c " & $ExtCmd, @TempDir, @SW_MINIMIZE)

MsgBox(64, "Result", "Return code was: " & $RET)
Yeah, that one seems to work just fine, saying: "Return code was: 2"

Is that OK that the return code is 2? How do I know that? Sorry if the question is trival...

Thank you so much for your help and contribution!

Cheers :)

Warmly,Narciso

Link to comment
Share on other sites

Doesn't seem to work :D I am getting this:

==> Variable used without being declared.:

$Pid = Run(@ComSpec & " /c " & $ExtCmd, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD + STDERR_CHILD)

$Pid = Run(@ComSpec & " /c " & $ExtCmd, @TempDir, @SW_MINIMIZE, ^ ERROR

>Exit code: 0 Time: 0.228

Can you fix that for me?

No big deal. The $STDOUT_CHILD and STDERR_CHILD flags are constants. I didn't show the include you need, just put this at the top:

#include <constants.au3>oÝ÷ Ù.q©Þ½éãºË]®mëÚ®&ëÛ¬zØ^+^­©oj[±«­¢+ØÀÌØíA¥ôIÕ¸¡
½µMÁµÀìÅÕ½Ðì½ÅÕ½ÐìµÀìÀÌØíáÑ
µ°QµÁ¥È°M]}5%9%5%i°Ø¤ìØôÀÌØíMQ=UQ}
!%1¬ÀÌØíMQII}
!%1

Yeah, that one seems to work just fine, saying: "Return code was: 2"

Is that OK that the return code is 2? How do I know that? Sorry if the question is trival...

Thank you so much for your help and contribution!

Cheers :)

What '2' means is up to your Perl script (and you are starting to sound like you don't have that yet, either). i.e if your Perl script has this in it, then and exit code of 2 means "Panic Mode Detected":

# Exit on panic mode error
if ($PanicMode > 0) {
    exit 2;
} else {
    print "So far, so good.  Continuing...";
}
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

No big deal. The $STDOUT_CHILD and STDERR_CHILD flags are constants. I didn't show the include you need, just put this at the top:

#include <constants.au3>oÝ÷ Ù.q©Þ½éãºË]®mëÚ®&ëÛ¬zØ^+^­©oj[±«­¢+ØÀÌØíA¥ôIÕ¸¡
½µMÁµÀìÅÕ½Ðì½ÅÕ½ÐìµÀìÀÌØíáÑ
µ°QµÁ¥È°M]}5%9%5%i°Ø¤ìØôÀÌØíMQ=UQ}
!%1¬ÀÌØíMQII}
!%1
Thanks, now it works excellent, saying "StdOut was: Hello, this is coming from Perl printout" and "ErrOut was: "

What '2' means is up to your Perl script (and you are starting to sound like you don't have that yet, either). i.e if your Perl script has this in it, then and exit code of 2 means "Panic Mode Detected":

# Exit on panic mode error
if ($PanicMode > 0) {
    exit 2;
} else {
    print "So far, so good.  Continuing...";
}
A bit confused about this panic mode... The first version of your script causes no stderr on exiting Perl script and the other one detects 2, the Panic Mode as you call it. Don't get it as the Perl code is quite simple and should exit with code 0. You can have a look at the Perl code below:

#!c:/Perl/bin/perl

print "Hello, this note comes from Perl :)";

Thanks in advance for your comment.

Have a nice day!!! :)

Warmly,Narciso

Link to comment
Share on other sites

Thanks, now it works excellent, saying "StdOut was: Hello, this is coming from Perl printout" and "ErrOut was: "

A bit confused about this panic mode... The first version of your script causes no stderr on exiting Perl script and the other one detects 2, the Panic Mode as you call it. Don't get it as the Perl code is quite simple and should exit with code 0. You can have a look at the Perl code below:

#!c:/Perl/bin/perl

print "Hello, this note comes from Perl :)";

Thanks in advance for your comment.

Have a nice day!!! :)

They were examples of mutually exclusive ways of seeing output from the Perl script. Either read StdOut, or use numeric exit codes. The two examples cannot be commingled. And StdErr is not the same thing as %ERRORLEVEL%. StdErr is a console stream of error messages. If there aren't any errors, there won't be any StdErr text in the stream. A numeric return code is only returned once when the Perl script exits. $PanicMode is not a standard Perl variable, I made it up as an example of some kind of status you might want a Perl script to return to the AutoIt script that ran it.

:D

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

Well, I hope I get it more or less. My point is why on earth the return value of a simple "Hello World" Perl script is 2. Shouldn't it be 0 meaning that the script ended successfully. Maybe the question belongs to Perl forum rather than here but I have a feeling the problem is kind of general, isn't it?

Warmly,Narciso

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...