Sign in to follow this  
Followers 0
sciosalvi

How to insert a script inside a script?

16 posts in this topic

Hey guys, I'm trying to define a string to be a another script, so that it can be run independently of the first one and not interrupt the process.

How can it be done? When I define a string variable, does it needs to be all in the same line? How can I convert a regular script to a onliner that Autoit would then reconstruct properly?

Share this post


Link to post
Share on other sites



For example, let's say I have this script here, the original without conversion to one line:

ConsoleWrite('! = Red' & @CRLF)
ConsoleWrite('> = Blue' & @CRLF)
ConsoleWrite('- = Orange' & @CRLF
ConsoleWrite('+ = Green' & @CRLF)

How could I convert it to one line, like this for example, and either have it run like this or convert it back to the first version?

ConsoleWrite('! = Red' & @CRLF) & @CRLF & ConsoleWrite('> = Blue' & @CRLF) & @CRLF & ConsoleWrite('- = Orange' & @CRLF) & @CRLF & ConsoleWrite('+ = Green' & @CRLF)

Share this post


Link to post
Share on other sites

Why do you need to run it independently? ConsoleWrite is being done in a fraction of a second.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Wow, you can add more than one lines of codes with a + mark? Another good thing to know :)

Share this post


Link to post
Share on other sites

You are simply adding the return values of the listed functions.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

No matter what, one line or not, the operations will occur from left to right.  They will never process at the same time (well...they can, but they would need to run as their own process, and those new processes would still be started from left to right).  What's the real thing you are attempting to do?

This sleeps for 8 seconds, not the max of the sleeps:

$i = TimerInit()
$i2 = Sleep(5000) + Sleep(2000) + Sleep(1000)
ConsoleWrite(TimerDiff($i) & @CRLF)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Hey guys, thanks for the responses.

I wasn't very clear.

I don't need to run the commands in the same line, what I want to do is have multitasking in a way.

Other functions need to run all the time, so I want to insert into my main script another script so that it can run in parallel, by being called externally.

I know how to do that, what I don't know is how to create a string with the whole script.

So, basically I need to adapt or compress a script with different lines into a text that can be converted by Autoit into a string that is the script.

Or know a way to store multiline text inside one string.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Like john stated, you can 'install' the au3 files into a compiled script, which durring run time copies out to a location, you can then execute the through a run command (not runwait).

Helpfile = command line paramater:

Form1: AutoIt3.exe [/ErrorStdOut] [/AutoIt3ExecuteScript] file [params ...]
Execute an AutoIt3 Script File

OR, if it is just one line of code:

 

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

If he want's to run functions in line (blocking), then that's fine.  He want's to run in parallel, so would need to create a second process to execute.

Like including a UDF, without actually including it :).

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Hey guys!

I'm still not being understood, let me give you an example.

I want to have one script that contains, in the same file, another script.

Example (not saying it works, but this is something similar to what I need). The actual functions have no importance:

 

 

#include <MsgBoxConstants.au3>

$external_script = "ConsoleWrite('! = Red' & @CRLF) + ConsoleWrite('> = Blue' & @CRLF) + ConsoleWrite('- = Orange' & @CRLF) + ConsoleWrite('+ = Green' & @CRLF)"
Run(@AutoItExe & "$external_script")

While 1
    Sleep(3000)
    MsgBox(0,"","Test")
WEnd

 

I could also use WriteFile to copy the string "$external_script" to disk if necessary.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I think you are not understanding what is being suggested. Write script 1, then use FileInstall to include it in script 2, as has been suggested:

FileInstall("C:\Script2.au3", @TempDir & "\Script2.au3")

Then call that script1 with the syntax jdelaney gave you in post 12. Whole lot easier than writing the thing on the fly.

Edited by JLogan3o13
2 people like this

√-1 2^3 ∑ π, and it was delicious!

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