Home > Running a Script > Running a Script in Debug Mode > Debug Mode in Action on a Sample Script

Debug Mode in Action on a Sample Script

This article shows how to debug a sample script.

The script to debug must be first loaded in WinTask Editor. Here is the script :



The script launches notepad, and in a loop types Hello concatenated with the index i. A second index j is there only for the tutorial purpose.

The easiest way to use Debug mode is to put the cursor just before the line where the execution must stop and then watch the variable i. So you put the cursor in front of line 8 and you press F8, keyboard shortcut for Run to cursor (or in the Debug toolbar, you can click the Run to cursor icon  or select Debug/Run to cursor menu). The Editor window with the cursor on line 8 looks like:

And after pressing F8, the Editor window is minimized, notepad is launched, Hello1 is typed in notepad, the script stops and the Editor window comes back to focus. Note the green arrow pointing the line where the script stopped (the pointed line is not yet executed).



Before executing line 8, you want to know the value of i. In the Output pane (the one in the bottom), click Watch Tab if it is not on focus, and click Add new variable:



And in <name>, type the name of the variable to watch, so i and press Enter. The value of the variable i is displayed:
 

Now, let's use a breakpoint. You want to watch the content of the variable j at each iteration, so just before the script executes the line 9 wich contains j=j-1. To insert a breakpoint, put the cursor in front of line 9 and press F9 (or click the Breakpoint icon  in the Debug toolbar, or select Debug/Insert breakpoint menu option). The Editor window now looks like:



Continue the script execution by pressing F5 (or click the Start/Continue debugging icon  in the Debug toolbar, or select Debug/Start/Continue debugging menu option).

The script stops just before executing line 9:
 



In order to see the value of the variable j, click Add new variable in the Output pane:



And in <name> write j. The value of j is now displayed, note too that the i variable value has been updated:
 


You can now loop and at each iteration, on the line where the breakpoint is, the Editor window comes back to focus and in the Output window, you can see the values of variables i and j. So press F5 to go on with the execution in Debug mode and watch:



If you want to stop the execution in Debug mode, press Shift+F5 (or click the Stop debugging icon  in the Debug toolbar or select Debug/Stop debugging menu option).

Note that as soon as you close the Editor, all the Debug environment is lost (breakpoints and Watch variables). And the Watch variables list is shared with all the opened scripts within the Editor window.

See also

About Debug Mode
Step by Step Execution
Step Over
Step Out
Run To Cursor
Breakpoints
Watch Variables
Debug Toolbar