From Xojo Documentation

Revision as of 21:53, 27 January 2022 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)

Used by console (or command-line) applications on Windows, macOS, and Linux.

Run UnhandledException
BugVersion fa-lock-32.png ExecutableFile fa-lock-32.png RegionCode fa-lock-32.png
BuildDateTime fa-lock-32.png MajorVersion fa-lock-32.png StageCode fa-lock-32.png
Copyright fa-lock-32.png MinorVersion fa-lock-32.png Version fa-lock-32.png
Description fa-lock-32.png NonReleaseVersion fa-lock-32.png
Daemonize DoEvents


A console application differs from a desktop application in that it contains no graphical user interface and works only from the command line. In macOS, 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 Chooser window. This will create a new project without items for the default window and menubar. The Navigator will only have the App class, which is subclassed from ConsoleApplication instead of Application or WebApplication.

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

When you create a Desktop application, the program execution begins in the Opening event of the DesktopApplication 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. Press Control-C for force a console app to quit.

NOTE: By design, console applications do not have a main event loop. It implies that classes relying on such event loop will not work as expected, like Timers or sockets. See the DoEvents method to see how to use Timers and sockets in a console application.

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.

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 application")
Return -1
End If
End If

See Also

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