Class

# ConsoleApplication

<div class="rst-class">

forsearch

</div>

Console

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

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

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                      | Type                                 | Read-Only | Shared |
|-----------------------------------------------------------|--------------------------------------|-----------|--------|
| `BugVersion<consoleapplication.bugversion>`               | `Integer</api/data_types/integer>`   | ✓         |        |
| `BuildDateTime<consoleapplication.builddatetime>`         | `DateTime</api/data_types/datetime>` | ✓         |        |
| `Copyright<consoleapplication.copyright>`                 | `String</api/data_types/string>`     | ✓         |        |
| `Description<consoleapplication.description_property>`    | `String</api/data_types/string>`     | ✓         |        |
| `ExecutableFile<consoleapplication.executablefile>`       | `FolderItem</api/files/folderitem>`  | ✓         |        |
| `MajorVersion<consoleapplication.majorversion>`           | `Integer</api/data_types/integer>`   | ✓         |        |
| `MinorVersion<consoleapplication.minorversion>`           | `Integer</api/data_types/integer>`   | ✓         |        |
| `NonReleaseVersion<consoleapplication.nonreleaseversion>` | `Integer</api/data_types/integer>`   | ✓         |        |
| `ProcessID<consoleapplication.processid>`                 | `Integer</api/data_types/integer>`   | ✓         |        |
| `RegionCode<consoleapplication.regioncode>`               | `Integer</api/data_types/integer>`   | ✓         |        |
| `StageCode<consoleapplication.stagecode>`                 | `Integer</api/data_types/integer>`   | ✓         |        |
| `Version<consoleapplication.version>`                     | `String</api/data_types/string>`     | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                      | Parameters                                              | Returns                            | Shared |
|-------------------------------------------|---------------------------------------------------------|------------------------------------|--------|
| `Daemonize<consoleapplication.daemonize>` |                                                         | `Boolean</api/data_types/boolean>` |        |
| `DoEvents<consoleapplication.doevents>`   | milliseconds As `Integer</api/data_types/integer>` = 10 |                                    |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                        | Parameters                                                    | Returns                            |
|-------------------------------------------------------------|---------------------------------------------------------------|------------------------------------|
| `Run<consoleapplication.run>`                               | args() As `String</api/data_types/string>`                    | `Integer</api/data_types/integer>` |
| `UnhandledException<consoleapplication.unhandledexception>` | error As `RuntimeException</api/exceptions/runtimeexception>` | `Boolean</api/data_types/boolean>` |

## Property descriptions

<div id="consoleapplication.bugversion">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.BugVersion

**BugVersion** As `Integer</api/data_types/integer>`

> The Bug version of the <span class="title-ref">ConsoleApplication</span>. This can only be set in the IDE, but you can read the value in your code.
>
> Typically version numbers are written as 1.2.3.4 (MajorVersion.MinorVersion.BugVersion.NonReleaseVersion).
>
> This property is read-only.
>
> Put all the individual versions together to create the full version:
>
> ``` xojo
> Var fullVersion As String
> fullVersion = MajorVersion.ToString + "." + MinorVersion.ToString + "." + BugVersion.ToString + "." + NonReleaseVersion.ToString
> ```

<div id="consoleapplication.builddatetime">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.BuildDateTime

**BuildDateTime** As `DateTime</api/data_types/datetime>`

> Contains the date and time when the application was built.
>
> You can also access the `CreationDateTime<folderitem.creationdatetime>` property of the application's `FolderItem</api/files/folderitem>` by calling App.ExecutableFile.CreationDate.
>
> This property is read-only.

<div id="consoleapplication.copyright">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.Copyright

**Copyright** As `String</api/data_types/string>`

> Copyright information of the <span class="title-ref">ConsoleApplication</span>.
>
> Copyright usually contains the application name, version number and copyright information.
>
> This property is read-only.
>
> Logs the app version:
>
> ``` xojo
> System.DebugLog("Copyright: " + App.Copyright)
> ```

<div id="consoleapplication.description_property">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.Description

**Description** As `String</api/data_types/string>`

> The description of the application, corresponding to the version information.
>
> This property is read-only.
>
> This property can be set only in the IDE.

<div id="consoleapplication.executablefile">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.ExecutableFile

**ExecutableFile** As `FolderItem</api/files/folderitem>`

> Points to the actual executable file even if it is inside a bundle.
>
> This property is read-only.
>
> To get the app executable name:
>
> ``` xojo
> Var appName As String = App.ExecutableFile.Name
> ```

<div id="consoleapplication.majorversion">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.MajorVersion

**MajorVersion** As `Integer</api/data_types/integer>`

> The major version of the <span class="title-ref">ConsoleApplication</span>, corresponding to the version information. The range is from 0 to 255. This can only be set in the IDE, but you can read the value in your code.
>
> This property is read-only.
>
> Typically version numbers are written as 1.2.3.4 (MajorVersion.MinorVersion.BugVersion.NonReleaseVersion).
>
> Put all the individual versions together to create the full version:
>
> ``` xojo
> Var fullVersion As String
> fullVersion = MajorVersion.ToString + "." + MinorVersion.ToString + "." + BugVersion.ToString + "." + NonReleaseVersion.ToString
> ```

<div id="consoleapplication.minorversion">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.MinorVersion

**MinorVersion** As `Integer</api/data_types/integer>`

> Minor version of the <span class="title-ref">ConsoleApplication</span>, corresponding to the version information. The range is from 0 to 255. This can only be set in the IDE, but you can read the value in your code.
>
> This property is read-only.
>
> Typically version numbers are written as 1.2.3.4 (MajorVersion.MinorVersion.BugVersion.NonReleaseVersion).
>
> Put all the individual versions together to create the full version:
>
> ``` xojo
> Var fullVersion As String
> fullVersion = MajorVersion.ToString + "." + MinorVersion.ToString + "." + BugVersion.ToString + "." + NonReleaseVersion.ToString
> ```

<div id="consoleapplication.nonreleaseversion">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.NonReleaseVersion

**NonReleaseVersion** As `Integer</api/data_types/integer>`

> The NonRelease version of the <span class="title-ref">ConsoleApplication</span>, corresponding to the version information. Sometimes referred to as the build number. This can only be set in the IDE, but you can read the value in your code.
>
> This property is read-only.
>
> Typically version numbers are written as 1.2.3.4 (MajorVersion.MinorVersion.BugVersion.NonReleaseVersion).
>
> If AutoIncrementVersionInformation is checked, the IDE increases NonReleaseVersion by one each time you build your project, but not when you run it.
>
> Put all the individual versions together to create the full version:
>
> ``` xojo
> Var fullVersion As String
> fullVersion = MajorVersion.ToString + "." + MinorVersion.ToString + "." + BugVersion.ToString + "." + NonReleaseVersion.ToString
> ```

<div id="consoleapplication.processid">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.ProcessID

**ProcessID** As `Integer</api/data_types/integer>`

> Returns the system process ID for the app that you would see in something like Activity Monitor (macOS) or Task Manager (Windows).
>
> This property is read-only.

<div id="consoleapplication.regioncode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.RegionCode

**RegionCode** As `Integer</api/data_types/integer>`

> The Region Code of the application, corresponding to the version information. Not supported on Windows. This property can be set only in the IDE.
>
> This property is read-only.

<div id="consoleapplication.stagecode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.StageCode

**StageCode** As `Integer</api/data_types/integer>`

> Stage Code of the application, corresponding to the version information.
>
> This property is read-only.
>
> Use the four Application class constants to set/get the Stage. Stage can be set only in the IDE.
>
> | Value | Description |
> |-------|-------------|
> | 0     | Development |
> | 1     | Alpha       |
> | 2     | Beta        |
> | 3     | Final       |

<div id="consoleapplication.version">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.Version

**Version** As `String</api/data_types/string>`

> Version of the <span class="title-ref">ConsoleApplication</span>.
>
> This property is read-only.
>
> This property can be set only in the IDE.
>
> Typically version numbers are written as 1.2.3.4.
>
> Version is displayed by the file information windows on macOS (Finder, Get Info) and Windows (Windows Explorer, Properties).

## Method descriptions

<div id="consoleapplication.daemonize">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.Daemonize

**Daemonize** As `Boolean</api/data_types/boolean>`

> Converts the app from a regular console app to a daemon process that runs in the background on macOS or Linux.
>
> Since daemonized console apps cannot be run from the IDE, you should build and test as a non-daemonized console app and then daemonize it when you build. Use `System<system.log>` to handle debugging.
>
> Although you can also use the Daemonize method on macOS, Apple would rather you use [launchd](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html) to start daemon processes.
>
> To create a background console application on Windows, you need to use `ServiceApplication</api/console/serviceapplication>`.
>
> A typical use of the Daemonize method is as follows:
>
> ``` xojo
> #If Not DebugBuild Then ' Do not try to daemonize a debug build
>   If (args(1) = "start" Or args(1) = "-d") Then ' Check for command-line parameter to daemonize
>     If Not App.Daemonize Then
>       System.Log(System.LogLevelCritical, "Could not daemonize the app.")
>       Return -1
>     End If
>   End If
> #EndIf
> ```

<div id="consoleapplication.doevents">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.DoEvents

**DoEvents**(milliseconds As `Integer</api/data_types/integer>` = 10)

> Yields time back to your app so that it can handle other events.
>
> ``` xojo
> ' In the Run event of your console application  
> Var consoleTimer As New MyTimerSubclass
>
> consoleTimer.RunMode = Timer.RunModes.Multiple ' Don't forget this one
> consoleTimer.Period = 1000 ' Call every second
>
> Do
>   App.DoEvents
> Loop
> ```

## Event descriptions

<div id="consoleapplication.run">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.Run

**Run**(args() As `String</api/data_types/string>`) As `Integer</api/data_types/integer>`

> Code in this event is run when the console app starts running. The console app ends when this event finishes.
>
> *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.
>
> On macOS and Linux, the *args()* array contains the passed arguments as *unescaped* and *unquoted* values:
>
> - **Unescaped**: some characters need to be escaped to be passed on a terminal command line, i.e. preceded by a backslash character. *args()* values contain the character without the leading backslash.
> - **Unquoted**: instead of escaping some characters, single-quotes or double-quotes can be used. Quotes are removed in *args()* values.
>
> For example, passing the following command line from a terminal:
>
> ``` plain
> /path/to/my/application -a --name="A quoted string parameter" --file=~/An\\ escaped\\ path
> ```
>
> results in the following *args()* array:
>
> | Value | Description                      |
> |-------|----------------------------------|
> | 0     | /path/to/my/application          |
> | 1     | -a                               |
> | 2     | --name=A quoted string parameter |
> | 3     | --file=~An escaped path          |
>
> If your app has concluded successfully, it should return 0 from this event. If not, it should return some kind of non-zero error code.

<div id="consoleapplication.unhandledexception">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

ConsoleApplication.UnhandledException

**UnhandledException**(error As `RuntimeException</api/exceptions/runtimeexception>`) As `Boolean</api/data_types/boolean>`

> Occurs when a `RuntimeException</api/exceptions/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.
>
> The UnhandledException event returns a `Boolean</api/data_types/boolean>`. By default, the application writes an error message to stderr. Return `True</api/language/true>` to suppress output to stderr.

## Notes

A console application differs from a desktop application in that it contains no graphical user interface and works only from the command line. On 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</api/language/app>` class, which is subclassed from <span class="title-ref">ConsoleApplication</span> instead of `DesktopApplication</api/user_interface/desktop/desktopapplication>` or `WebApplication</api/web/webapplication>`.

Because a console application has no windows or menus of its own, it communicates with the user through the `Print</api/console/print>` and `Input</api/console/input>` commands or the `StandardInputStream</api/console/standardinputstream>` and `StandardOutputStream</api/console/standardoutputstream>` classes, which provide equivalent functionality.

When you create a Desktop application, the program execution begins in the Opening event of the `DesktopApplication</api/user_interface/desktop/desktopapplication>` class and halts when you call the `Quit</api/language/quit>` method or the user quits your application by choosing File =\> Quit. Your program will stay loaded in memory and running until a `Quit</api/language/quit>` command is received.

A console application behaves differently from a desktop application. The program execution begins in the `Run<consoleapplication.run>` event of the <span class="title-ref">ConsoleApplication</span> class and terminates when you exit the `Run<consoleapplication.run>` event or call the `Quit</api/language/quit>` method. In other words, the entire application executes inside of the `Run<consoleapplication.run>` event. Press `Ctrl+C` for force a console app to quit.

<div class="note">

<div class="title">

Note

</div>

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</api/language/timer>` or sockets. See the `DoEvents<consoleapplication.doevents>` method to see how to use `Timers</api/language/timer>` and sockets in a console application.

</div>

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</api/language/loops/while...wend>` loop in the Run event.

A `ServiceApplication</api/console/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 GDK, or CUPS.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### The Daemonize method

A typical use of the Daemonize method is as follows:

``` xojo
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
```

## Compatibility

|                       |              |
|-----------------------|--------------|
| **Project Types**     | Console, Web |
| **Operating Systems** | All          |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `Input</api/console/input>`, `Print</api/console/print>`, `StdErr</api/console/stderr>`, `StdIn</api/console/stdin>`, `StdOut</api/console/stdout>` methods; `ServiceApplication</api/console/serviceapplication>`, `StandardInputStream</api/console/standardinputstream>`, `StandardOutputStream</api/console/standardoutputstream>` classes; `TargetConsole</api/compiler_directives/targetconsole>` constant

</div>
