Sign in to follow this  
Followers 0
Ravel

quick question about calling a script...

17 posts in this topic

I am curious if anyone knows if it is possible to call a script from inside another script? Such as I run script "A" and it calls various other scripts and ends.

Share this post


Link to post
Share on other sites



Hi,

yes 4 options are possible:

exe run exe

exe run au3

au3 run exe

au3 run au3

what do you need?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I am curious if anyone knows if it is possible to call a script from inside another script? Such as I run script "A" and it calls various other scripts and ends.

Why not just
#include <yourfile.au3>oÝ÷ Ù.ºË®±ëaÈî²×è­û§rبÆî·*.q©ÚÊ.±è­¶î©è¶«±Êâ¦Òn²Únµ¦®¶­sb6æ6ÇVFRÖöæ6P

at the top of the script you want to include.

Edit: Forgot a "#"

Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

I wrote a UDF for such a thing:

http://www.autoitscript.com/forum/index.ph...c=29088&hl=

The Kandie Man :lmao:


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Cool I will try that. Also another question...

"C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe" /game:starwars

I am trying to get this to run from the run command

ie: run("C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe" /game:starwars")

however i keep getting an error. Anyone know what i can do to resolve this issue?

Share this post


Link to post
Share on other sites

This is the original script that i am using to try and call others from

HotkeySet('{ESC}', 'Terminate')

opt ("WinTitleMatchMode",4)

WinwaitActive("randomprogram")

Run("E:\Internet Downloads\Scripts\file3.au3")

Run("E:\Internet Downloads\Scripts\file1.au3")

Run("E:\Internet Downloads\Scripts\file2.au3")

Func Terminate()

Exit

EndFunc

Share this post


Link to post
Share on other sites

Hi,

should be

Run("C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe /game:starwars")

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Cool I will try that. Also another question...

"C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe" /game:starwars

I am trying to get this to run from the run command

ie:

run("C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe"  /game:starwars")

however i keep getting an error. Anyone know what i can do to resolve this issue?

Anyone have any ideas on this?

Share this post


Link to post
Share on other sites

Hi,

should be

Run("C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe /game:starwars")

So long,

Mega

Ok let me try that :lmao:

Share this post


Link to post
Share on other sites

Ok let me try that :lmao:

Run('"C:\Program Files\Sony\Station\LaunchPad\LaunchPad.exe"' & " /game:starwars")

that one worked. THanks alot I appreciate it!!

Share this post


Link to post
Share on other sites

This is the original script that i am using to try and call others from

HotkeySet('{ESC}', 'Terminate')
opt ("WinTitleMatchMode",4)
WinwaitActive("randomprogram")

Run("E:\Internet Downloads\Scripts\file3.au3")

Run("E:\Internet Downloads\Scripts\file1.au3")

Run("E:\Internet Downloads\Scripts\file2.au3")
Func Terminate()
    Exit
EndFunc
[/quote]

In reference to the above script is there some unique way that it has to be written to get each of the files to spawn from one script? I am looking to have the files either be in script form or complied. Any ideas? :lmao:

Share this post


Link to post
Share on other sites

Any ideas anyone?

Share this post


Link to post
Share on other sites

I wrote a UDF for such a thing:

http://www.autoitscript.com/forum/index.ph...c=29088&hl=

The Kandie Man :lmao:

Hey... i was looking at the post that you wrote, however I cant make heads or tails of how to apply that to my purpose of running the three external scripts. I am not sure what I am supposed to change to make it work for me? Anyway you could clear that up for me? Thanks in advance.

Share this post


Link to post
Share on other sites

Hi,

first of all, please do not double post. Second why not combine the scripts to one? Third, you can do they way you tried. What is your exact problem?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Any ideas anyone?

think about what you are doing!! Run() starts a PROGRAM !! AU3 is not a program. It's a text file with AutoIT commands. So you should specify the interpreter as EXECUTABLE and the script as parameter!

BTW: there are other ways to do it, like this: Compile all your scripts and then call the *.exe with run().

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 *

Share this post


Link to post
Share on other sites

Here is an example of how to use my UDF in your script:

#include "ExternalExecute.au3"
HotkeySet('{ESC}', 'Terminate')
opt ("WinTitleMatchMode",4)
WinwaitActive("randomprogram")

;~ Run("E:\Internet Downloads\Scripts\file3.au3")
;~ Run("E:\Internet Downloads\Scripts\file1.au3")
;~ Run("E:\Internet Downloads\Scripts\file2.au3")

;you can make the above the below with my UDF(User Defined Functions)

;you may install the files to a temporary directory like this:
Fileinstall("E:\Internet Downloads\Scripts\file3.au3",@tempdir & "\file3.au3",1)
Fileinstall("E:\Internet Downloads\Scripts\file1.au3",@tempdir & "\file1.au3",1)
Fileinstall("E:\Internet Downloads\Scripts\file2.au3",@tempdir & "\file2.au3",1)


;You may then run them like this:
_FileAU3Ex(@tempdir & "\file3.au3");read more about this any my other two functions in the external execute.udf
_FileAU3Ex(@tempdir & "\file1.au3")
_FileAU3Ex(@tempdir & "\file2.au3")








;if you want, you  may execute only certain parts of the script and therefore have all the scripts in one file.au3

;~ _FileAU3Ex("E:\Internet Downloads\Scripts\file.au3",1,50)
;the above line will execute the script from line 1 to 50 and no more, please make sure it doesn't call a function at the bottom of the script, this will cause errors


;~ _FileAU3Ex("E:\Internet Downloads\Scripts\file3.au3",51,60)
;the above will execute the script from line 51 to 60, once again, make sure all functions that are called from those lines are within those lines


;~ _FileAU3Ex("E:\Internet Downloads\Scripts\file3.au3",61,0)
;the above script will run from line 61 to the last line(line 0 = last line), same as above for function calling







;you may also wish to call only a specific function that doesn't rely on the external script, another words, it doesn't call on any other functions in that script.
;can read more about it as it is documented in the udf file itself.  if you have further questions, feel free to ask.



Func Terminate()
    Exit
EndFunc

oÝ÷ Øw«z+&ÈLmz¹ÚL^^jíßW+&ºË[zZqçbØ^±©~]z¶¬¶¬r¸©µ¦è½ê+Ê°Y`zÖ§w%¹×®º+b¦ºËlj÷­+²«¨´Lmz¹ÚL^^jíêºZÚeiÇ¢¶)íëçè׫jëh×6

;===============================================================================
;
; Description:      Executes External AU3 Script
; Parameter(s):     $v_filename - Location of external AU3 script
;                   $i_startline    - [optional] Line to start reading in the external script, default is 1 which is the first line
;                   $i_endline    - [optional] Line to terminate reading of external script, default is 0 which is end of file
; Requirement(s):   None
; Return Value(s):  On Success - 1
;                   On Failure - 0  and Set
;                                   @ERROR to:  1 - Invalid $v_filename
;                                               2 - Invalid $i_startline
;                                               3 - Invalid $i_endline
; Author(s):        The Kandie Man
; Note(s): This function allows a user to execute an external script from a compiled autoit executeable by using a function in the compiled executable.
;  The script pauses and the external script is run.  Once the external script finishes, the compiled script continues its execution.
;===============================================================================
#include <file.au3>
#include <array.au3>
Func _FileAU3Ex($v_filename, $i_startline = 1, $i_endline = 0)
    $v_tempexecutefile = @TempDir & "\execute.au3"
    If Not FileExists($v_filename) Then
        SetError(1)
        Return 0
    EndIf
    If $i_startline < 1 Then
        SetError(2)
        Return 0
    EndIf
    If $i_endline < $i_startline And $i_endline <> 0 Then
        SetError(3)
        Return 0
    EndIf
    If $i_startline = 0 And $i_endline = -1 Then
;~      RunWait(@ComSpec & ' /c "' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $v_filename & '"', "", @SW_HIDE)
        RunWait(@AutoItExe & ' /AutoIt3ExecuteScript "' & $v_filename & '"', "", @SW_HIDE)
    Else
        Dim $av_temparray
        _FileReadToArray($v_filename, $av_temparray)
        $i_numelements = UBound($av_temparray)
        If $i_numelements < $i_endline Then
            SetError(3)
            Return 0
        EndIf
        _FileWriteFromArray($v_tempexecutefile, $av_temparray, $i_startline, $i_endline)
;~      RunWait(@ComSpec & ' /c "' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $v_tempexecutefile & '"', "", @SW_HIDE)
        RunWait(@AutoItExe & ' /AutoIt3ExecuteScript "' & $v_tempexecutefile & '"', @TempDir, @SW_HIDE)
        FileDelete($v_tempexecutefile)
        Dim $av_temparray = 0 ;free up memory
    EndIf
    Return 1
EndFunc   ;==>_FileAU3Ex
;===============================================================================
;
; Description:      Executes Function in External AU3 Script
; Parameter(s):     $v_filename - Location of external AU3 script
;                   $v_func    - The function to call without (), example "terminate", not "terminate()"
;                   $v_parameters    - [optional] The parameters that will by put inside the (), seprataed by commas.  The entire thing should be a string in quotes.
; Requirement(s):   None
; Return Value(s):  On Success - Return Value of Function called
;                   On Failure - "error"  and Set
;                                   @ERROR to:  1 - Invalid $v_filename
;                                               2 - Could not get what the function called returned
; Author(s):        The Kandie Man
; Note(s): Sorry for the weird return value on error, the reason for this is so that the return value doesn't conflict with the failure return value of the function called.
;  The script pauses and the external function is run.  Once the external function finishes, the compiled script continues its execution.
;IMPORTANT:  If you are using FileInstall and need the external files that are installed in order to run the function correctly, you must write a function with the various fileinstalls and call the function immidiately
;after the last #include.  If you have no includes, it must be the first line.
;This Function isn't idiot-proof.  Calling an external function that doesn't exist or with incorrect parameters will result in an autoit error
;===============================================================================
Func _FileAU3ExFunc($v_filename, $v_func, $v_parameters = "")
    $v_tempexecutefile = @TempDir & "\executefunc.au3"
    If Not FileExists($v_filename) Then
        SetError(1)
        Return 0
    EndIf
    Dim $av_temparray
    _FileReadToArray($v_filename, $av_temparray)
    Dim $i_counter = 1
    While 1
        _ArraySearch($av_temparray,"#include",$i_counter)
        If @error = 6 Then ExitLoop
        $i_counter += 1
    WEnd
    _ArrayInsert($av_temparray, $i_counter + 1, 'INIWrite("' & $v_tempexecutefile & '.ini", "Function", "Return",' & $v_func & "(" & $v_parameters & "))")
    _ArrayInsert($av_temparray, $i_counter + 2, "Exit")
    _FileWriteFromArray($v_tempexecutefile, $av_temparray, 1)
    RunWait(@AutoItExe & ' /AutoIt3ExecuteScript "' & $v_tempexecutefile & '"', @TempDir, @SW_HIDE)
    $v_return = IniRead($v_tempexecutefile & ".ini", "Function", "Return", "ERROR")
    FileDelete($v_tempexecutefile)
    FileDelete($v_tempexecutefile & '.ini')
    Dim $av_temparray = 0 ;clear memory
    If $v_return = "ERROR" Then
        SetError(2)
        Return "ERROR"
    EndIf
    Return $v_return
EndFunc   ;==>_FileAU3ExFunc
;===============================================================================
;
; Description:      Assosciates AU3 Files With a compiled version of itself so that
; Parameter(s):     None, you must devote an entire script to this function.  You may not place this function in an already coded script
; Requirement(s):   None
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0 - Only does this if you attempt to execute this function in an uncompiled autoitscript
; Author(s):        The Kandie Man
; Note(s): This function is a stand alone function.  No other functions or code should be executed in the script apart from maybe a fileinstall or
; an #include.  This is a very specific and unique function.  When compiled and sent to a target user's machine, it will associate the .extau3 extension with
;itself and install itself on the target user's machine.  You may now rename a .a3x or .au3 script to a .extau3 extension and send it to the target user's machine
;where the script will be executed as if they have autoit installed on their system.
;===============================================================================
Func _FileAU3Associate()
    If @Compiled = 0 Then
        Return 0
    EndIf
    If @AutoItExe = @ProgramFilesDir & "\AutoItExternal\AutoItExt.exe" And $CmdLine[0] > 0 Then
        Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $CmdLine[1] & '"')
    ElseIf @AutoItExe = @ProgramFilesDir & "\AutoItExternal\AutoItExt.exe" And $CmdLine[0] = 0 Then
        If Not IsDeclared("msgboxanswer34632") Then Dim $msgboxanswer34632
        $msgboxanswer34632 = MsgBox(308, "Remove?", "This program runs .extau3 files.  Since you have executed this file directly no .extau3 file was specified." & @CRLF & @CRLF & "If you remove this program you will no longer be able to run .extau3 files!" & @CRLF & @CRLF & "Are you sure you want to remove this program from your computer?")
        Select
            Case $msgboxanswer34632 = 6 ;Yes
                Run(@ComSpec & " /c " & 'FTYPE ExternalAutoit=', "", @SW_HIDE)
                Run(@ComSpec & " /c " & 'ASSOC .extau3=', "", @SW_HIDE)
                $openhandle3425 = FileOpen(@TempDir & "\remove.bat", 2)
                FileWrite($openhandle3425, ":start" & @CRLF & 'del "' & @AutoItExe & '"' & @CRLF & 'IF EXIST "' & @AutoItExe & '" goto start' & @CRLF & 'RD "' & @ProgramFilesDir & '\AutoItExternal"')
                FileClose($openhandle3425)
                Run(@TempDir & "\remove.bat", "", @SW_HIDE)
            Case $msgboxanswer34632 = 7 ;No
        EndSelect
        Exit
    Else
        FileCopy(@AutoItExe, @ProgramFilesDir & "\AutoItExternal\AutoItExt.exe", 9)
        Run(@ComSpec & " /c " & 'FTYPE ExternalAutoit="' & @ProgramFilesDir & '\AutoItExternal\AutoItExt.exe" "%1"', "", @SW_HIDE)
        Run(@ComSpec & " /c " & 'ASSOC .extau3=ExternalAutoit', "", @SW_HIDE)
    EndIf
    Return 1
EndFunc   ;==>_FileAU3Associate

I hope that helps.

-The Kandie Man :lmao:


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Thanks. I had come up with a temp solution, but this may prove to be effective too. I will have to test it out once i get home.

Share this post


Link to post
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
Sign in to follow this  
Followers 0