Jump to content

How to insert a script inside a script?


Recommended Posts

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?

Link to comment
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)
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.
Link to comment
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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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