Jump to content

How to run scripts with scripts


Blog
 Share

Recommended Posts

The topic says it all. Is it possible to use a script to run another .au3 script file?

The RUN function only seems to like executables like .exe

The #include "...au3" appears to run the script once, which is nice, but I want to run it multiple times. Using #include twice gives me an error about having declared functions with the same name twice.

Any suggestions?

I can give you a more lengthy description of my problem if needed.

Thanks in advance!

Link to comment
Share on other sites

Well, I would personally suggest that you wrap the commands in the include file into a function (i.e. Func RunMe()...EndFunc)...but you can also do:

MsgBox(0, "test", $x)

Dim $x = 0
While 1
    #include <include.au3>
    $x += 1
WEnd
I do truly suggest the FIRST method...it becomes much easier to manage in that way...

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

If you move the functions of the #included file into another one and call that file once, you can then call the original #included file as many times as you like.

<{POST_SNAPBACK}>

That is a very dumb suggestion. Files should only be included once intentionally. Doing it more than once is a sign of poor design and not understanding what #include does.
Link to comment
Share on other sites

That is a very dumb suggestion.  Files should only be included once intentionally.  Doing it more than once is a sign of poor design and not understanding what #include does.

<{POST_SNAPBACK}>

Yeah, that's what i was wondering about, why someone would want to include more than once... Blog, when you include a script, the functions in that script become availible to the including script, as if they were written into it. You can then call the functions as many times as needed, recursively or otherwise.
Link to comment
Share on other sites

...The RUN function only seems to like executables like .exe...

<{POST_SNAPBACK}>

Like others have said, there might be better ways to do this...

In response to the one sentence in your post that I've quoted above:

Run(@ComSpec & " /c" & "C:\Temp\msg.au3","", @SW_HIDE)

or just

Run("C:\Program Files\AutoIt3\AutoIt3.exe C:\Temp\msg.au3")

or

...there are more ways to do this with "Run", but you get the point.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Blog hasn't replied back to any of this yet, but isn't this really what he is trying to do:

Run(@ProgramFilesDir & "\AutoIt3\autoit3.exe C:\some-path\some-file.au3", "C:\")

And then either repeat that line or put it in a loop with a Sleep command?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Blog hasn't replied back to any of this yet, but isn't this really what he is trying to do:

Run(@ProgramFilesDir & "\AutoIt3\autoit3.exe C:\some-path\some-file.au3", "C:\")

And then either repeat that line or put it in a loop with a Sleep command?

Dale

<{POST_SNAPBACK}>

yes, but he seems to already have the include statement, that's why i went that way with it...
Link to comment
Share on other sites

First of all, thanks for the replies.

I didn't know that the Run function could be given autoit3.exe with the .au3 file! That's what I was looking for at first.

But it turns out that a new environment is created. So variables in the original script were not recognized... it didn't solve my problem.

So I tried Alex Peter's suggestion - moved all the Func's in the file I wanted to #include multiple times into a different file to #include once. Now I didn't get any errors when #including multiple times, and that script is run in the same environment. Problem solved; that was what I wanted to do!

Sure, it might not be the proper way to use the #include statement, but it got the job done! Thanks everybody!

Link to comment
Share on other sites

Sure, it might not be the proper way to use the #include statement, but it got the job done! Thanks everybody!

You can also drive nails if you hit them just right with a car. Does that mean you shouldn't strive to find a better way to do it?
Link to comment
Share on other sites

I'm guessing that this may be a case of not understanding what functions are all about - back to CS101.

The following pseudo-code will execute the code in Function Abc, Xyz, Abc and Xyz and then it will exit.

If this is really what you want to do, please read through the tutorials in the helpfile so that you understand the basics of program flow in AutoIt (actually, this is basic program logic not unique to AutoIt).

Be warned that there is seldom much tolerance in this forum for questions taht demonstrate a lack of understanding of basic programming logic. Please study the helpfile and examples in the forum to get the basics down or prepare to get flamed.

; Main script logic

Abc()
Xyz()
Abc()
Xyz()

Exit

Func Abc()
  ; put code here you want to reuse
EndFunc

Func Xyz()
  ; put different code here you want to reuse
EndFunc

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

That is a very dumb suggestion.  Files should only be included once intentionally.  Doing it more than once is a sign of poor design and not understanding what #include does.

<{POST_SNAPBACK}>

The help seems to encourage "multiple includes of the same file". I'm not defending the practice, just making a point and perhaps a suggestion for a change to the docs. I do realize that the example in the help file is meant to be simplistic and not a class in code design.

;;; TIME.AU3 ;;;

MsgBox(0,"", "The time is " & @HOUR & ":" & @MIN & ":" & @SEC)

;;; SCRIPT.AU3 ;;;

#include "TIME.AU3"

MsgBox(0,"", "Example")

#include "TIME.AU3"

Exit

; Running script.au3 will output three message boxes:

; one with the time, one with 'Example', and another with the time.

So, let me see if I can explain the way that I've been driving nails:

;;; Clear-temp.au3 ;;;

code to clear some temp files - if certain other files are present

There are no user defined functions inside of Clear-temp

I run Clear-temp as a stand alone au3 several times a day.

;;; Main-script.au3 ;;;

include Clear-temp

does some things in an app

include Clear-temp

Are you saying that it would be better to do this:

;;; Clear-temp.au3 ;;;

ct()

Func ct()

code to clear some temp files - if certain other files are present

EndFunc

;;; Main-script.au3 ;;;

include Clear-temp

does some things in an app

ct()

@DaleHohm,

I studied the help file before I ever used "include".

Flame suit is on. :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

That is a very dumb suggestion.  Files should only be included once intentionally.  Doing it more than once is a sign of poor design and not understanding what #include does.

<{POST_SNAPBACK}>

I never suggested (and wouldn't suggest) anything of the sort -- it was merely an observation.

I could have subsequently stated 'I suggest that you rewrite your code to adopt user-defined functions and only require one inclusion' but that wasn't necessary.

Link to comment
Share on other sites

I personally never call code in an included file. Files I intend to include define functions and global variables (Usually constants). I even use a different file extension for files I intend to be include files and treat them more like C/C++ header files than actual AutoIt scripts. So neither of your examples are "good". Instead:

#include "ClearTemp.au3"
ClearTemp()
; Code
ClearTemp()

; ClearTemp.au3
Func ClearTemp()
   ; Do things
EndFunc
Link to comment
Share on other sites

If I make Clear-temp.au3 a pure function, I would need 3 files:

;;; Clear-temp.au3 ;;;

Func ct()

code to clear some temp files - if certain other files are present

EndFunc

;;; Main-script.au3 ;;;

include Clear-temp

ct()

does some things in an app

ct()

;;; Run-Clear-temp.au3 ;;; to run as a stand alone script

include Clear-temp

ct()

Not that having 3 files is a problem... but leaving Clear-temp as non-function code and including it more than once in the main script is looking pretty good to me right now. I like the idea of using a different file ext on include files. Might just have to adopt that practice. Thanks for your time.

I wonder if I should change my custom member title from:

"Clear as mud?"

to

"Happily driving nails with cars."

[size="1"][font="Arial"].[u].[/u][/font][/size]

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