Sign in to follow this  
Followers 0
gte

Is it possible that autoit errors out (won't compile) because a string is too long?

13 posts in this topic

I have autoit creating an exectuable that will also create a batch file, and I'm creating the batch file with the code below, hard coding it and separating each line with the & @crlf & _

It appears that at no matter what text I have, it fails at a certain point, so I removed a few lines in different places and it will then run and not fail. Any thoughts?

I have the first snippet of code that works

$filewritedata = '@echo off' & @crlf & _
                            '' & @crlf & _
                            'set startDate=%date% ' & @crlf & _
                            'set startTime=%time% ' & @crlf & _
                            '' & @crlf & _
                            'set sdy=%startDate:~10%' & @crlf & _
                            'set /a sdm=1%startDate:~4,2% - 100' & @crlf & _
                            'set /a sdd=1%startDate:~7,2% - 100' & @crlf & _
                            'set /a sth=%startTime:~0,2%' & @crlf & _
                            'set /a stm=1%startTime:~3,2% - 100' & @crlf & _
                            'set /a sts=1%startTime:~6,2% - 100' & @crlf & _
                            '' & @crlf & _
                            '' & @crlf & _
                            '' & @crlf & _
                            'echo. +++++++++++++++++++++++++++  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. %sth%:%stm%:%sts% %sdm%-%sdd%-%sdy% >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. This change was made via the scheduled task batch file >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. User who made the change %username% >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. [The usernameinput boxes were checked, and the create notification task at a later date was checked]' & @crlf & _
                            'd:\temp\sc stop "fecs notification" ' & @crlf & _
                            'd:\temp\sleep 3' & @crlf & _
                            'd:\temp\Sc.exe query "FECS NOTIFICATION" |d:\temp\Find.exe "STOPPED"' & @crlf & _
                            'echo. %ERRORLEVEL%' & @crlf & _
                            'If %ERRORLEVEL% EQU 0 (' & @crlf & _
                            'echo. GOTO run' & @crlf & _
                            ') Else (' & @crlf & _
                            'echo.  The notification service could not be stopped.  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatefailureemail.exe' & @crlf & _
                            'GOTO :END' & @crlf & _
                            ')' & @crlf & _
                            ':run' & @crlf & _
                            'echo. Notification service stopped  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. The original HKLM\software\dma\fecs\applications\notification\aedib "AC_AS400" key was: ' & RegRead('HKLM\software\dma\fecs\applications\notification\aedib', 'AC_AS400') & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\reg add "hklm\software\dma\fecs\applications\notification\aedib" /v AC_AS400 /t REG_SZ /d "user=' & $usernameupdate & ',password=' & $passwordupdate & ',table=' & $tableupdate & '" /f' & @crlf & _
                            'echo. The new HKLM\software\dma\fecs\applications\notification\aedib "AC_AS400" key will be: ' & $usernameupdate & ',password=' & $passwordupdate & ',table=' & $tableupdate & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. The original hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400 "Default Libraries" key was: '  & RegRead('\\' & $server & '\hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400', 'DefaultLibraries') & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\reg add "hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400" /v DefaultLibraries /t REG_SZ /d "' & $sqldefaultupdate & ' ' & $newlibrarylistupdate & '" /f' & @crlf & _
                            'echo. The new hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400 "Default Libraries" key will be: ' & $sqldefaultupdate & ' ' & $newlibrarylistupdate & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\sleep 1' & @crlf & _
                            'echo. Notification service not started   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'sleep 5' & @crlf & _
                            'SetLocal' & @crlf & _
                            'Set SVC="FECS NOTIFICATION"' & @crlf & _
                            'd:\temp\Sc.exe query %SVC% |d:\temp\Find.exe "STOPPED"' & @crlf & _
                            'echo. %ERRORLEVEL%' & @crlf & _
                            'If %ERRORLEVEL% EQU 0 (' & @crlf & _
                            'echo. The service was successfully stopped.' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatesuccessemail.exe' & @crlf & _
                            ') Else (' & @crlf & _
                            'echo. The could not be stopped' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatefailureemail.exe' & @crlf & _
                            ')' & @crlf & _
                            '' & @crlf & _
                            ''

and this snippet of code that does not (look for the astericks) the lines added are below and marked with *** in the code

'echo. >> D:\dma\logfiles\librarylistchange.log' & @crlf & _

'echo. >> D:\dma\logfiles\librarylistchange.log' & @crlf & _

'echo. >> D:\dma\logfiles\librarylistchange.log' & @crlf & _

$filewritedata = '@echo off' & @crlf & _
                            '' & @crlf & _
                            'set startDate=%date% ' & @crlf & _
                            'set startTime=%time% ' & @crlf & _
                            '' & @crlf & _
                            'set sdy=%startDate:~10%' & @crlf & _
                            'set /a sdm=1%startDate:~4,2% - 100' & @crlf & _
                            'set /a sdd=1%startDate:~7,2% - 100' & @crlf & _
                            'set /a sth=%startTime:~0,2%' & @crlf & _
                            'set /a stm=1%startTime:~3,2% - 100' & @crlf & _
                            'set /a sts=1%startTime:~6,2% - 100' & @crlf & _
                            '' & @crlf & _
                            '' & @crlf & _
                            '' & @crlf & _
                            'echo. +++++++++++++++++++++++++++  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. %sth%:%stm%:%sts% %sdm%-%sdd%-%sdy% >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. This change was made via the scheduled task batch file >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. User who made the change %username% >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. [The usernameinput boxes were checked, and the create notification task at a later date was checked]' & @crlf & _
                            'd:\temp\sc stop "fecs notification" ' & @crlf & _
                            'd:\temp\sleep 3' & @crlf & _
                            'd:\temp\Sc.exe query "FECS NOTIFICATION" |d:\temp\Find.exe "STOPPED"' & @crlf & _
                            'echo. %ERRORLEVEL%' & @crlf & _
                            'If %ERRORLEVEL% EQU 0 (' & @crlf & _
                            'echo. GOTO run' & @crlf & _
                            ') Else (' & @crlf & _
                            'echo.  The notification service could not be stopped.  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatefailureemail.exe' & @crlf & _
                            'GOTO :END' & @crlf & _
                            ')' & @crlf & _
                            ':run' & @crlf & _
                            'echo. Notification service stopped  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. The original HKLM\software\dma\fecs\applications\notification\aedib "AC_AS400" key was: ' & RegRead('HKLM\software\dma\fecs\applications\notification\aedib', 'AC_AS400') & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\reg add "hklm\software\dma\fecs\applications\notification\aedib" /v AC_AS400 /t REG_SZ /d "user=' & $usernameupdate & ',password=' & $passwordupdate & ',table=' & $tableupdate & '" /f' & @crlf & _
                            'echo. The new HKLM\software\dma\fecs\applications\notification\aedib "AC_AS400" key will be: ' & $usernameupdate & ',password=' & $passwordupdate & ',table=' & $tableupdate & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. The original hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400 "Default Libraries" key was: '  & RegRead('\\' & $server & '\hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400', 'DefaultLibraries') & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\reg add "hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400" /v DefaultLibraries /t REG_SZ /d "' & $sqldefaultupdate & ' ' & $newlibrarylistupdate & '" /f' & @crlf & _
                            'echo. The new hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400 "Default Libraries" key will be: ' & $sqldefaultupdate & ' ' & $newlibrarylistupdate & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\sleep 1' & @crlf & _
                            'echo. Notification service not started   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
 ***                         'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
 ***                         'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
 ***                         'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'sleep 5' & @crlf & _
                            'SetLocal' & @crlf & _
                            'Set SVC="FECS NOTIFICATION"' & @crlf & _
                            'd:\temp\Sc.exe query %SVC% |d:\temp\Find.exe "STOPPED"' & @crlf & _
                            'echo. %ERRORLEVEL%' & @crlf & _
                            'If %ERRORLEVEL% EQU 0 (' & @crlf & _
                            'echo. The service was successfully stopped.' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatesuccessemail.exe' & @crlf & _
                            ') Else (' & @crlf & _
                            'echo. The could not be stopped' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatefailureemail.exe' & @crlf & _
                            ')' & @crlf & _
                            '' & @crlf & _
                            ''

Share this post


Link to post
Share on other sites



If a single line of the script is more than 4095 characters, it will fail. You can assemble larger strings inside a variable like this:

Global $sLongString = "4095 characters..."
$sLongString &= "...yet another 4095 characters..."

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

For future reference using the continuation characters " _" space followed by an underscore does not break up the line of code as far as Autoit is concerned. It is still on one line of code. " _" just makes it easier for a human to read.

Use the method shown by PsaltyDS to break very long lines of code like the one in your script


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

I'm thinking that if you have to do this then you need to think again about how you're coding your script.

WBD

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Psalty

I've done it like the below

and the error message I'm getting is this?

C:\Documents and Settings\*****\Desktop\changelibrarylist1.au3(752,18) : ERROR: syntax error

$filewritedata &=

~~~~~~~~~~~~~~~^

C:\Documents and Settings\*****\Desktop\changelibrarylist1.au3 - 1 error(s), 0 warning(s)

$filewritedata = '@echo off' & @crlf & _
                            '' & @crlf & _
                            'set startDate=%date% ' & @crlf & _
                            'set startTime=%time% ' & @crlf & _
                            '' & @crlf & _
                            'set sdy=%startDate:~10%' & @crlf & _
                            'set /a sdm=1%startDate:~4,2% - 100' & @crlf & _
                            'set /a sdd=1%startDate:~7,2% - 100' & @crlf & _
                            'set /a sth=%startTime:~0,2%' & @crlf & _
                            'set /a stm=1%startTime:~3,2% - 100' & @crlf & _
                            'set /a sts=1%startTime:~6,2% - 100' & @crlf & _
                            '' & @crlf & _
                            '' & @crlf & _
                            '' & @crlf & _
                            'echo. +++++++++++++++++++++++++++  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. %sth%:%stm%:%sts% %sdm%-%sdd%-%sdy% >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. This change was made via the scheduled task batch file >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. User who made the change %username% >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. [The usernameinput boxes were checked, and the create notification task at a later date was checked]' & @crlf & _
                            'd:\temp\sc stop "fecs notification" ' & @crlf & _
                            'd:\temp\sleep 3' & @crlf & _
                            'd:\temp\Sc.exe query "FECS NOTIFICATION" |d:\temp\Find.exe "STOPPED"' & @crlf & _
                            'echo. %ERRORLEVEL%' & @crlf & _
                            'If %ERRORLEVEL% EQU 0 (' & @crlf & _
                            'echo. GOTO run' & @crlf & _
                            ') Else (' & @crlf & _
                            'echo.  The notification service could not be stopped.  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatefailureemail.exe' & @crlf & _
                            'GOTO :END' & @crlf & _
                            ')' & @crlf & _
                            ':run' & @crlf & _
                            'echo. Notification service stopped  >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. The original HKLM\software\dma\fecs\applications\notification\aedib "AC_AS400" key was: ' & RegRead('HKLM\software\dma\fecs\applications\notification\aedib', 'AC_AS400') & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\reg add "hklm\software\dma\fecs\applications\notification\aedib" /v AC_AS400 /t REG_SZ /d "user=' & $usernameupdate & ',password=' & $passwordupdate & ',table=' & $tableupdate & '" /f' & @crlf & _
                            'echo. The new HKLM\software\dma\fecs\applications\notification\aedib "AC_AS400" key will be: ' & $usernameupdate & ',password=' & $passwordupdate & ',table=' & $tableupdate & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. The original hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400 "Default Libraries" key was: '  & RegRead('\\' & $server & '\hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400', 'DefaultLibraries') & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\reg add "hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400" /v DefaultLibraries /t REG_SZ /d "' & $sqldefaultupdate & ' ' & $newlibrarylistupdate & '" /f' & @crlf & _
                            'echo. The new hklm\SOFTWARE\ODBC\ODBC.INI\AC_AS400 "Default Libraries" key will be: ' & $sqldefaultupdate & ' ' & $newlibrarylistupdate & ' >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'd:\temp\sleep 1' & @crlf & _
                            'echo. Notification service not started   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo. +++++++++++++++++++++++++++ >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
          $filewritedata &= 'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'echo.   >> D:\dma\logfiles\librarylistchange.log' & @crlf & _
                            'sleep 5' & @crlf & _
                            'SetLocal' & @crlf & _
                            'Set SVC="FECS NOTIFICATION"' & @crlf & _
                            'd:\temp\Sc.exe query %SVC% |d:\temp\Find.exe "STOPPED"' & @crlf & _
                            'echo. %ERRORLEVEL%' & @crlf & _
                            'If %ERRORLEVEL% EQU 0 (' & @crlf & _
                            'echo. The service was successfully stopped.' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatesuccessemail.exe' & @crlf & _
                            ') Else (' & @crlf & _
                            'echo. The could not be stopped' & @crlf & _
                            '\\s030089\d$\temp\librarylistupdatefailureemail.exe' & @crlf & _
                            ')' & @crlf & _
                            '' & @crlf & _
                            ''

If a single line of the script is more than 4095 characters, it will fail. You can assemble larger strings inside a variable like this:

Global $sLongString = "4095 characters..."
$sLongString &= "...yet another 4095 characters..."

:)

Edited by gte

Share this post


Link to post
Share on other sites

I'm thinking that if you have to do this then you need to think again about how you're coding your script.

WBD

I second WideBoyDixon's notion on this one.

PsaltyDS gave you the answer to your original question, but really, I think you should be looking at FileWriteLine to build your batch file.

(Though really shouldn't you be coding the whole thing in AutoIt?)

Share this post


Link to post
Share on other sites

No, it can't be coded that way

My exe creates a scheduled task and batch file, but the batch file is dynamic and since an exe can't compile another exe, it has to be a batch file.

I WISH I could have written it all in auto it. It uses the filewrite command though, after the dynamic batch file is created

I second WideBoyDixon's notion on this one.

PsaltyDS gave you the answer to your original question, but really, I think you should be looking at FileWriteLine to build your batch file.

(Though really shouldn't you be coding the whole thing in AutoIt?)

Share this post


Link to post
Share on other sites

No, it can't be coded that way

Yes, it can.

My exe creates a scheduled task and batch file, but the batch file is dynamic and since an exe can't compile another exe, ...

Yes, it can.

...it has to be a batch file.

I WISH I could have written it all in auto it. It uses the filewrite command though, after the dynamic batch file is created

I don't understand what FileWrite() has to do with it, but Aut2Exe.exe can be run from a command line, or by another script (see the help file).

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

... and since an exe can't compile another exe, it has to be a batch file. ...

Maybe...

http://www.autoitscript.com/forum/index.ph...st&p=572932

There are other scripts to do this as well.

I would leave UPX out of the mix.


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

Share this post


Link to post
Share on other sites

Psalty,

Can you provide some example code?

Sure. This is a parent script that can run from SciTE or compiled. It writes an .au3 child script file, then compiles that to an .exe, then runs it:
Global $sTempAU3 = @ScriptDir & "\TempAU3.au3"
Global $sTempEXE = @ScriptDir & "\TempEXE.exe"
Global $sAutoItDir = RegRead("HKLM\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")
Global $sExtCmd = $sAutoItDir & '\Aut2Exe\Aut2exe.exe /in "' & $sTempAU3 & '" /out "' & $sTempEXE & '"'

; Array containing lines of AutoIt code
Global $avCode[4] = [3]
$avCode[1] = 'Global $sMsg1 = "Child Execution time = " & @YEAR & "\" & @MON & "\" & @MDAY'
$avCode[1] &= ' & " " & @HOUR & ":" & @MIN & ":" & @SEC'; Assembling a long line in parts
$avCode[2] = 'Global $sMsg2 = "Parent Execution time was: ' & @YEAR & '\' & @MON & '\' & @MDAY
$avCode[2] &= ' ' & @HOUR & ':' & @MIN & ':' & @SEC & '"'
$avCode[3] = 'MsgBox(64, "Child Script", $sMsg2 & @CRLF & $sMsg1)'

; Create source file
Global $hTempAU3 = FileOpen($sTempAU3, 2); 2 = overwrite
For $n = 1 To UBound($avCode) - 1
    FileWriteLine($hTempAU3, $avCode[$n])
Next
FileClose($hTempAU3)

; Compile EXE
Global $RET = RunWait($sExtCmd, @ScriptDir, @SW_SHOW)

; Run the new EXE
RunWait($sTempEXE, @ScriptDir, @SW_SHOW)
MsgBox(64, "Parent Script", "Done.")

Note that proper quoting is the tricky part. $sMsg2 contains the actual macro values for date/time, while $sMsg1 contains macro references to generate different values when the child script runs.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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