Sign in to follow this  
Followers 0
Kammamuri

shell-program and error handling

11 posts in this topic

Hi! so..I understand that making a program without errors is better then just ignoring the errors and this is why i rarely use this method. However sometimes i need to test a program for longer periods of time without being able to check it so i've made this little shell-program:

#include <Constants.au3>

Global $n

HotKeySet("{ESC}", "Terminate")

$n = 0

While 1

   If ProcessExists("iexplore.exe") Then ProcessClose("iexplore.exe") ;the program will open ie and i dont want to have too many opened at the same time
   RunWait(@AutoItExe & ' /ErrorStdOut  "C:\Program Directory\Program Name.exe"')
   
   $n = $n + 1
   
WEnd

;Terminate
Func Terminate()
   Local $ErrorLog = FileOpen("ErrorLog.txt",2)
   FileWrite($ErrorLog, "The program crashed " & $n & " times")
   FileClose($ErrorLog)
   Exit 0
EndFunc

it gives me the number of times the program has crashed and was forced to restart on a txt file. I've tried to get on this txt file also the Error message by reading the stdout stream but i don't seem to be able to find a way to make it work. I've tried to use "run" instead of "runwait" in combination with "if processexists..." but it hasn't worked at all. If anyone could show me how to get the error message on a txt file it would be great! :D thanks in advance

Share this post


Link to post
Share on other sites



Why are you trying to run the program with the AutoIt exe? Does this even run for you at all?

Why not just use Run() with the StdErr option (see the help file) and loop until it isn't running any more and read the StdIO stream of the program, that should tell you if the program says anything on the Error stream?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi, thanks for the suggestion. I've tried the following code.  

#include <Constants.au3>

Global $n

HotKeySet("{ESC}", "Terminate")

$n = 0

While 1

   If ProcessExists("TheBeast v0.75.exe") = 0 Then
      If ProcessExists("iexplore.exe") Then ProcessClose("iexplore.exe")
      Local $foo = Run(@AutoItExe & ' /ErrorStdOut  "direcotory\programname.exe"', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
   EndIf
   
   Local $line
   While 1
      $line = StderrRead($foo)
      If @error Then ExitLoop
      Local $ErrorLog = FileOpen("ErrorLog.txt",2)
      FileWrite($ErrorLog, $line)
      FileClose($ErrorLog)
   WEnd
   
   Sleep(1000)
WEnd

;Terminate
Func Terminate()
   Exit 0
EndFunc

but i'm experiencing the following issue. The first thing the child program should do is open a txt file, read some information and use it to browse to a web site (for instance it reads ".com" and goes to "google.com" or "it" and goes to "google.it") using the command FileOpen("name of file.txt") since this file is in the same folder. However, for some reason when the child program gets launched by the parent program it doesn't read the file! (it works correctly when i manually start it). any idea what may cause the problem/how to fix it? .. it works just fine with the code i've posted in the previous post too

Share this post


Link to post
Share on other sites

I'll ask again, why are you using the @AutoItExe macro to run your child program? I'm pretty sure that is most of your problem.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I'm not sure why I was using it.. it seemed to be the only working syntax :

thanks for the help

this works: (i also had to remove @SystemDir)

Local $foo = Run('C:\...\name.exe /ErrorStdOut', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

now i correcly get the error on the txt file, for example:

C:Users...ProgramName.exe (5103) : ==> Subscript used with non-Array variable.:
 
problem is my program has about 2000 lines (so 5103 makes no sense), is it possible to get the right line at which the error occurs?

Share this post


Link to post
Share on other sites

Kammamuri,

The "too big" line number is because of the include files. I explain how to get the correct number >here. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks! I think i understand your explanation in the other topic, but how do I "run Obfuscator using the /STRIPONLY parameter, when compiling my script"? .. when i compile a script I usually go to the .au3 file I want to compile, right click on it and then click on "Compile Script (x64)".. I've looked at http://www.autoitscript.com/autoit3/scite/docs/Obfuscator.html but it says something about AutoIt3Wrapper (which I haven't heard before). I've added the lines

#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so 

before the #include(s) in my program but when i compile it (using the above procedure) nothing happens.

ps. sorry if I'm slow to understand but I autoit is the only programming language I "know" (except a little bit of Pascal and C) and English isn't may native language either :)

Share this post


Link to post
Share on other sites

Kammamuri,

Did you download and install the full SciTE4AutoIt3 package as explained in the other thread? :huh:

You get AutoIt3Wrapper and lots of other goodies to help you code in AutoIt. :)

M23
 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I had something (I program with SciTE) but it must have been an old version. Anyway, I re-downloaded everything and now it works just fine! :D thanks a lot!

I'll have to get used to the new light blue color of the back ground :)

Share this post


Link to post
Share on other sites

Kammamuri,

Open SciTEConfig (look under the <Tools> menu or press Ctrl-1 with an .au3 file open) and you can change colours and many other values within SciTE. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

BTW, as a follow up to this, unless you NEED the script to be compiled to run at all, don't compile it until it's working 100%. This way you can run it in SciTE (hit F5 to run it uncompiled), and if it encounters an error it will tell you the actual line the problem happens on, and/or the include that the problem is happening in.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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