Jump to content

Autoit script works until I try to run it frm Perl


mraymond
 Share

Recommended Posts

I have a simple AutoIT script that will Close my application. It is compled, and from the cygwin prompt it runs and closes my application as expected. It is an executable AUTOIT script, so I run it like this:

run LP_Close.exe

When I try to run this inside a Perl script, my application opens, but then the Autoit script I'm calling doesn't close the application like it does when I run from the command line. Why is this? How can I get it to work? Below is the contents of the AutoIT script and the Perl script. Note I am using cygwin on an XP machine.

------------------- THIS IS THE AUTOIT SCRIPT THAT IS TURNED INTO EXE

; Sleep for 8 seconds waiting for Logger Pro table cell to appear in edit mode

Sleep (8000)

; Activate the Logger Pro window so we can close it

WinActivate ( "Logger Pro -", "")

; Close Logger Pro

WinClose("Logger Pro -", "")

---------------------- THIS IS THE PERL SCRIPT THAT IS CALLING LP_Close.exe via backticks

#!/usr/bin/env perl

# This script requires having cygwin and Perl installed

# The script will generate a file called "cmbl-list.txt"

# which contains the paths to all the Experiment files.

# The program will then use this "cmbl-list.txt" file to

# open each Experiment in Logger Pro

print "* * * * * * * * * * * * * * * *\n";

print "* *\n";

print "* EXECTUTING FILE LAUNCHER *\n";

print "* *\n";

print "* * * * * * * * * * * * * * * *\n";

# the following command gets all the path names to any cmbl files

# and writes them to a text file called "cmbl-list.txt"

`find ./Experiments -iname "*cmbl" -print > cmbl-list.txt`;

# The following command opens the cmbl-list.txt file for input

# but if it can't find it, then it will choke and print a message

open(INFILE, "cmbl-list.txt") or die "Can't open cmbl-list.txt: $!";

while (<INFILE>)

{

# Write the variable $_ to a file, it is the path to the file to be opened in the application

open(DAT, ">Experiment_Path") || die("Can't open Experiment_Path

File.");

print DAT $_;

close(DAT);

# run the unix script that has command line to launch loggerpro with switches and the file path

`./Open_Experiment.sh`;

# run the Autoit script which will close the Logger Pro application

`run LP_Close.exe`;

}

# the following command closes the cmbl-list.txt file

close INFILE;

Link to comment
Share on other sites

try running notepad... does it run... does everything else run ok?

Lar.

Hi larry.

What I have discovered is that the reason my AutoIT script doesn't work (inside the Perl script WHILE loop) is because when my application is launched inside the Perl WHILE loop, it is a process waiting to end... so unless I manually close my application, that AutoIT script never gets called. I found this out when I changed the AutoIT script to just do a Mouse Click on the "X" box to close my application. When I manually closed the application I noticed my mouse curser move up to the top right of the screen and attempt a coordinate click. This proved to me that the process from the previous line in Perl had to complete first before it would call my AutoIT script (I'm newbie at Perl also). I guess I'm going to have to find another way to do this. I've been looking at some Fork() command, or possibilities of using AutoIT to launch the application and then open the file, but I have not figured out how to "Send" a $Line of text (sitting in the $Line variable) into the "File name:" field of the "Open" dialog so I can open the file in my application.

Link to comment
Share on other sites

Fork() command, or possibilities of using AutoIT to launch the application and then open the file, but I have not

fork() could help, however it fork() is not implemeted in all perl distributions for windows. What's the content of Open_Experiment.sh. Maybe there is a better way to solve your problem.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

fork() could help, however it fork() is not implemeted in all perl distributions for windows. What's the content of Open_Experiment.sh. Maybe there is a better way to solve your problem.

Cheers

Kurt

----------------------

The content of "Open_Experiment.sh" was:

read -r Epath < Experiment_Path

run loggerpro /log /noUI "$Epath"

----------------------- Thanks Kurt

That ran fine. It was able to open my application called "Logger Pro", with the swithes to start a log file, close any opened dialogs, and the file I wanted (via variable $Epath). The probem was that once "Open_Experiment.sh" exectuted... it had to end before it would run the Autoit script I planned to Close the application with. I have now solved this processing problem by just getting rid of the "Open_Experiment.sh" all together and created an AutoIT script now which launches the application. I am able to use the AutoIT piece of code:

send(string($line)

That sends the path to the field in the dialog. That opened up another can of worms though because this stupid windows dialog isn't capable of taking a whole path. I think I can solve it though by parsing out the slashes and sending each piece to the dialog until I get to the file I actually want to open. Just for the record though, the piece of AutoIT code I'm playing around with to test this out is:

$file = FileOpen("Experiment_Path", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open Experiment_Path file.")

Exit

EndIf

; Read in the Experiment Path from Experiment_Path file

$line = FileReadLine($file)

; Display the line we read into the variable just to prove we got it

; will remove this later once I get the rest of the script to work

MsgBox(0, "Line read:", $line)

Run("loggerpro.exe /log /noUI")

Sleep(7000)

Send("{ALT}f")

Send("o")

Sleep(3000)

send(string($line))

So.... I think I might be able to solve this task by parsing that variable out in some Autoit string functions I found. Whew! Newbie head hurts!

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