Jump to content

Scripts locks up


Recommended Posts

Hello,

I'm new to AutoIt, so I'm probably doing something wrong.

I adapted the sample Calculator-script so it opens a program, simulates some keypresses, waits 1 minute, then closes the program again.

After that, a web-page is opened.

But 9 times out of 10, the script just 'hangs'. I tried running it as au3 and as an exe, no difference.

Could somebody check if I did something wrong in the (very simple) code?

;
; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x/NT
; Author:        Jonathan Bennett (jon@hiddensoft.com)
; Author2:      Fire69
;
; Script Function:
;   Lets Media Companion scrape newly added TV Shows
;   Starts XBMC Library Update


; Run Media Companion
Run("C:\Program Files\Media Companion\Media Companion.exe")


; Wait for Media Companion to become active - it is titled "Media Companion"
WinWaitActive("Media Companion")


; Now that the Media Companion window is active, change it to TV Show mode
Send("{LALT}")
Send("{RIGHT}")
Send("{Down 2}") 
Send("{Enter}")

; Now that the mode is changed, let it scrape newly added episodes
Send("{LALT}")
Send("{RIGHT 2}")
Send("{Down 4}")
Send("{Enter}")

; Wait 1 minute for Media Companion to finish scraping
Sleep(60000)

; Now quit by sending a "close" request to Media Companion
WinClose("Media Companion")

; Now wait for Media Companion to close before continuing
WinWaitClose("Media Companion")

; Send URL to XBMC Webserver to start update of Video Library
ShellExecute("http://localhost/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)")


; Finished!
Edited by Fire69
Link to comment
Share on other sites

  • Moderators

Fire69,

First, welcome to the AutoIt forums. A good start - some code to work on and a clear question. I wish some other newcomers would do the same. :-)

Try adding some debugging lines to check whether the script arrives at particular points:

ConsoleWrite("Got here: " & @ScriptLineNumber & @CRLF)

and see if you can pinpoint the location where the script hangs. Nothing jumps out of the script as posted - but I would hazard a guess that it is the application not closing.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Fire69,

First, welcome to the AutoIt forums. A good start - some code to work on and a clear question. I wish some other newcomers would do the same. :-)

Try adding some debugging lines to check whether the script arrives at particular points:

ConsoleWrite("Got here: " & @ScriptLineNumber & @CRLF)

and see if you can pinpoint the location where the script hangs. Nothing jumps out of the script as posted - but I would hazard a guess that it is the application not closing.

M23

I have over 12K post on another tech-forum so I know what kind of posts some people can throw at you! :o

I'll try adding the code, thanks for the great tip. :D

The application does disappear, so I guess it's just after it closes that the script hangs. Maybe it's not detecting correctly that the program closed. Am I using the best way to detect this?

Link to comment
Share on other sites

Yes, this does happen. All the buttons should be pressed one after the other. It just simulates opening the menu, going right and down.

Is there a way to simulates function-keypresses? F2 and so? I couln't really find that.

@Melba23: I added the code in several places, but where should the message with the linenumbers appear? What is considered as the console in AutoIt? :D

Edited by Fire69
Link to comment
Share on other sites

  • Moderators

Fire69,

If you run from SciTE, ConsoleWrite results appear in the lower window.

Godly has made a good point - I often add a short Sleep() between menu commands to allow time for menus (particularly cascading ones!) to open.

And yes, you can Send F keys - from the Help file: Send("{F1} - {F12}")

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Fire69,

If you run from SciTE, ConsoleWrite results appear in the lower window.

Godly has made a good point - I often add a short Sleep() between menu commands to allow time for menus (particularly cascading ones!) to open.

And yes, you can Send F keys - from the Help file: Send("{F1} - {F12}")

M23

Ah, OK, got it :D

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Program Files\SABnzbd\scripts\ScrapeMCAndUpdateXBMC.au3"  
Got here: 21
Got here: 30
Got here: 39
Got here: 48
Got here: 54
>Exit code: 0   Time: 63.393

Everything seems normal.

The thing is, this script runs everytime Sabnzbd finishes downloading a new episode.

So when I queue up 10 episodes, it should run 10 times.

However, the most I got it to run consecutively is 3 or 4 times.

Then it hangs. The Media Companion program is closed so it got that far, but then nothing happens anymore.

If have to kill ScrapeMCAndUpdateXBMC.au3 (or .exe) through the Task Manager.

After that, Sabnzbd continues and the scripts functions again a couple of times.

Then it hangs again...

Must have missed the function keys in the Help. I know I looked for it! :D

I'll change that already, so the consecutive keypresses are already eliminated from the script. :o

Edited by Fire69
Link to comment
Share on other sites

Okay, little update.

I've been messing around a bit and disovered something.

First some backgroundinfo:

Sabnzbd starts a batch-file:

REM Rename .nfo to .info

cd /d %1
if exist %3.nfo ren %3.nfo %3.info


REM Lets MC scrape the episode and updates XBMC's Library

call "C:\Program Files\SABnzbd\scripts\ScrapeMCAndUpdateXBMC.au3"

So first an existing .nfo-file is renamed, then the au3-file is started.

I just started this batch-file myself about 5 times.

What happened? All 5 times Media Companion opened and closed again, as it should.

But 2 times the dos-box stayed open with this in it:

C:\Program Files\SABnzbd\scripts>REM Rename .nfo to .info

C:\Program Files\SABnzbd\scripts>echo.


C:\Program Files\SABnzbd\scripts>cd /d

C:\Program Files\SABnzbd\scripts>if exist .nfo ren .nfo .info

C:\Program Files\SABnzbd\scripts>echo.


C:\Program Files\SABnzbd\scripts>REM Lets MC scrape the episode and updates XBMC's Library

C:\Program Files\SABnzbd\scripts>call "C:\Program Files\SABnzbd\scripts\ScrapeMCAndUpdateXBMC.au3"

So it hangs there. DOS doesn't see the AutoIt-script finished and just keeps waiting for it.

And that's why Sabnzb doesn't continue, it's waiting for this to end.

Apparently, Sabnzb turns off the dos-output, so that's why I hadn't noticed this before.

Any ideas?

[edit]

I just commented out the line that sends the url to Internet Explorer and put it in the batch-file itself (through a .url-file).

After that, I ran the batch-file 15 times. Worked like a charm every time!

So sometimes the script doesn't exit correctly after the ShellExecute-command.

Had a look at the help-file, and there's an Exit-command (who would have thought! :o )

Added that to the end of the script, put the ShellExecute back in and tested the whole thing. Ran fine every time! Yeah!

Thanks for your time guys. :D

Edited by Fire69
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...