Debugging ScriptsBefore writing scripts of your own, make sure that your web server is correctly configured to run the Gsharp Web Edition and that the standard examples are working.
If the examples are running you are now ready to debug your own scripts. Debugging Your Own Scripts
Testing From the Command LineWhen running GSL scripts in cgi-bin, your browser may suppress any error messages, making it difficult for you to determine what went wrong. You may also see a message like "Document contains no data". To view these important messages you must run your scripts from the command line. For example:
This will run your script in exactly the same way as it is run by the CGI on the web server. On Windows you could also double click on the file in the explorer, but the output will probably disappear before you can read it. Windows only. If you find yourself testing from the command line a lot - then it probably makes sense to add the GsharpWE bin directory to your path so that you can just type "GsharpWE myscript.gsw". N.B. Before testing your own scripts, make sure that you can run the example script $UNIDIR/example/cgi-bin/gs_gallery.gsw. If this script works in the browser, but not from the command line you will need to make sure the environment variables set up for Gsharp by the browser (UNIDIR, LM_LICENSE_FILE, etc) are also set up in your command window. Debugging Scripts with the Gsharp Professional EditionThe Gsharp Professional Edition can be used to create your templates, but it can also be used to run your finished Gsharp Web Edition scripts. The advantage of running your scripts through the professional edition is that you can see exactly what is going on, see the error messages and explore the values in datasets. If your script references functions found only in GsharpWE, such as bounding_polygon() or the Java driver, then you can still test the rest of the script by making references to Gsharp Web Edition functions conditional. This can be done using the webedition() function: if webedition() then npoly = bounding_polygon(nvert, x, y); endif Handling Form Data - Method 1If you are writing a script than takes input from a form, then you should write it so that your variables take a default value if the form variable is not defined. This makes it possible to run the script from the command line or from within Gsharp Professional Edition. For example:text = "Hello Wide World"; if exists(WORK.FORM_text) text = WORK.FORM_text; page_1.view1.title.XuNtitleText = text; In this example the form data is used if present, but the script will run even if it is not specified or if debugging from the command line. A convenience function, HTMLget_value(), performs the steps above. This function is included in $UNIDIR/lib/libhtml.gsl. It can be used return a form value, if given, or a default value: HTMLget_value("text","Hello Wide World"); If your script only fails when a variable only has a certain value, HTMLget_value can be used to initialize a variable to the problem value. Handling Form Data - Method 2The second way of handling form data is to run your script from within the browser once and save all the form fields in a folder. Then run your script on the command line or from within Gsharp and get your form fields from the folder. To test a different set of form inputs just return to your form, enter the values, click submit to run your script again. The values of the form are saved again in a folder and will be used when you run Gsharp. The following code can be used: if webedition() then export_folder("c:\tmp\debug.fol"); else import_folder("c:\tmp\debug.fol"); endif The convenience function HTMLdebugform() in $UNIDIR/lib/libhtml.gsl will do the above for you. Just add it to the top of your script. e.g. include "$UNIDIR/lib/libhtml.gsl"; HTMLdebugform("c:\tmp\script2.fol"); |