Executing Scripts

WebScripter supports executing PERL, PHP and Ruby scripts from the command line, checking syntax and run time errors. You can run a script in the default mode by using the Run item in the toolbar or Run Script command (command-R) in the Editor menu.


Run toolbar item selecting the preview mode.

Topics

3.0 Run Modes

Depending on the specified run mode, files are executed differently and the results handled accordingly. Run modes can be set on a per project basis (the mode effects all scripts being run) or on an individual file basis (the mode overrides the project).

There are 3 run modes:

  • Run & Debug. Errors will be displayed in a split view pane above the editor or if no errors were detected the results will be previewed in the default mode (see below).
  • Run & Preview. The results from the script will be previewed in the default mode.
  • Run in Terminal Mode. The results from the script will be displayed in a split view pane above the editor, similar to a UNIX terminal like Apple's Terminal.app.
  • Check Syntax. A syntax check will be performed on the file and the results shown in a tool-tip (floating help) window.


Setting run mode in the project.


Setting run mode for a single file.

3.1 Debugging

By using the Run & Debug command you can get errors from your script during run time and be directed to the line where the file occurred or even redirected to the file where it originated from. Each language offers different information but at minimum the functionality mentioned above.

Debugging PHP

PHP does not include an interactive debugger but has good error handling functions to compensate. Beyond an error message PHP supplies other information that will help you understand where the bug occurred and what was happening in the run-time environment at the time.

Above the error list there will be a toolbar with buttons containing additional information about the error. The buttons are described below.

  • Stack Trace. If you select an error and click the Stack Trace button a popup window will appear with a stack trace showing which functions were called in subsequent calls to the function where the error occurred. Additionally, if you click the disclosure triangle next to the function name it will show the parameters and variables of the function when it was called.
  • Local Variables. All variables and their values in the function where the error occurred.
  • Classes. All classes declared in your script.
  • Class Tree. All classes in hierarchical view (showing inheritance).

Triggering Errors

Normally errors will be displayed if PHP detects a compile time error but you can also insert errors manually at any location to help debug your code by using the built-in PHP function trigger_error. The parameter you supply to the function will be displayed in the error list. For example:

trigger_error("error message");


Debugging a file in PHP.

Debugging Ruby

Ruby has basic error messages and a simple stack trace that corresponds with each error. If you click the disclosure triangle next to an error it's stack trace will be displayed. If you select a function from the trace the line it was declared will be selected in the editor.


Debugging a file in Ruby.

3.2 Terminal Mode

Terminal mode simulates a UNIX terminal (like Apple's Terminal.app) in appearance but only supports output, no input. Using terminal mode is faster then the command line because the command is generated for you and the output is available directly in WebScripter, so you don't need to switch applications. Terminal mode is helpful for quickly testing scripts that produce simple text results, instead of HTML.


Running a PHP script in terminal mode.

3.3 Checking Syntax

Syntax checks will show the results in a small popup window by the cursor and disappear when you start typing again.

Syntax checks can be performed in a few ways:

  1. Check Syntax command (command-;) in the Editor menu.
  2. Clicking and holding down the Run toolbar item, then selecting Check Syntax.
  3. Setting Check Syntax as the project or file run mode and running the script.


Checking syntax in a PHP script.

3.4 Script Arguments

WebScripter allows you to simulate command line arguments when running a script by using script arguments. The arguments you pass can be used to give a script dynamic state information that would normally be provided by a user, for example a GET string from an HTML form using the GET method. Note: The argument name and value are separated by the = symbol when supplied to the script.

The method arguments are available to the programmer vary in each language. Please refer to the manual on your preferred language and learn how it is used from the command line.


Setting script arguments in the file info window.

3.5 Command Line Preferences

By default PERL, PHP and Ruby are all installed with every recent version of OS X so you don't need to worry about suppling the path to the compiler. However, if you installed another version or the original moved for some reason you can set the path where WebScripter can find the compiler.

To change command line preferences follow these steps:

  • Open application preferences.
  • Select the Advanced pane.
  • Below the Command Line group set the path to the compiler of the desired language.


Setting command line preferences.

3.6 Aborting Execution

If there is a problem with a script executing it can be aborted by clicking the Abort button which appears in the editor toolbar every time a script is run. This is useful in the instance the script is performing a lengthy process you don't want to see the end of (like a network operation or an infinite loop).


Abort button in the editor toolbar.