ConsoleApplication
From Xojo Documentation
Used by console (or command-line) applications on Windows, macOS, and Linux.
Events | ||
|
Properties | ||||||||||||
|
Methods | ||||
|
Notes
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 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. 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 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