From Xojo Documentation

Revision as of 18:55, 19 November 2009 by WikiSysop (talk) (The Daemonize Method)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Used to run console applications on Windows, Mac OS X, and Linux.

Super Class



Name Parameters Return Type Description
Run Args() as String Integer Runs the application.

Args is an array of command line parameters that get passed to the application. The first parameter will always be the application itself. The return value will be passed to the operating system as the return value for the entire application. The encoding of Args() is operating system-specific. On NT-based systems, it is UTF-16. On Linux, it will be UTF-8, and so forth.

UnhandledException error as RuntimeException Occurs when a RuntimeException occurs that is not otherwise handled.

This event allows you to do any last-minute clean-up, but the application does not resume after this event. The application terminates after this event.


Name Type Description
Introduced 5.5
FolderItem Points to the actual executable file even if it is inside a bundle.


Name Parameters Return Type Description
Introduced 5.5
Boolean Converts the application from a regular console application to a daemon on Mac OS X or Linux.

See the Notes for ConsoleApplication for an example.

DoEvents [milliseconds as Integer] Yields time back to REALbasic so that it can handle other events.

The optional parameter specifies the amount of time you want the currently executing thread to sleep. If all threads are sleeping, then REALbasic yields back time to the system. This allows you to write applications that don't use up to 100% of the CPU during tight loops. Specifying zero milliseconds causes the next waiting thread to execute. A negative value specifies no sleep. The default is 10 milliseconds.


A console application differs from a desktop application in that it contains no graphical user interface and works only from the command line. In Mac OS X, a console application runs within the Terminal application; on Windows, it runs from the command line prompt, and on Linux it runs from the command line or a Terminal window.

To create a console application, choose File . New Project and choose Console Application from the New Project dialog box. This will create a new project without items for the default window and menubar. The Project Editor will only have the App class, which is subclassed from ConsoleApplication instead of Application.

Because a console application has no windows or menus of its own, it communicates with the user is through the Print and Input commands or the StandardInputStream and StandardOutputStream classes, which provide equivalent functionality.

When you create a GUI application, the program execution begins in the Open event of the Application class and halts when you call the Quit method or the user quits your application by choosing File . Quit. Your program will stay loaded in memory and running until a Quit command is received.

A console application behaves differently from a desktop application. The program execution begins in the Run event of the ConsoleApplication class and terminates when you exit the Run event or call the Quit method. In other words, the entire application executes inside of the Run event.

If you would like your application to behave in a more GUI-like way, where it continues to run until the user interacts with it, then you can do that by placing a While loop in the Run event.

A ServiceApplication is a special type of console application that is designed to run without user intervention of any kind. The typical type of service application is a an internet server, such as an HTTP, FTP, or WebDAV server, which is capable of running without any user logged into the machine.

On Linux, a console application does not require GTK, GDK, or CUPS.

A console application cannot use the Graphics class. This rules out the use of the Picture class, the Movie class, and all other graphics-oriented classes.

The Daemonize Method

A typical use of the Daemonize method is as follows:

If (args(1) = "start" or args(1) = "-d") then
If Not App.Daemonize then
System.Log( System.LogLevelCritical, "Could not daemonize the "_

See Also

Input, Print, StdErr, StdIn, StdOut methods; ServiceApplication, StandardInputStream, StandardOutputStream classes; TargetHasGUI constant.