env Operations

Code:

import std.env.*

main(): Int64 {
    println(getProcessId())
    println(getCommand())
    println(getCommandLine().toString())
    println(getWorkingDirectory().toString())
    atExit(printText)
    exit(0)
    return 0
}

func printText(): Unit {
    println("hello cangjie!")
}

The running result may be as follows: (In the output result, main is the command name of the current process. After the callback is complete, the current process exits.)

28481
main
[./main]
/root/code/workpalce/cangjie
hello cangjie!

Console Example

The following is a console example. In the example, two pieces of information entered by a user are received and returned to the user through standard output streams.

import std.env.*

main() {
    getStdOut().write("Input information 1:")
    var c = getStdIn().readln() // Input: Hello. What day is it today?
    var r = c.getOrThrow()
    getStdOut().writeln("The input information 1 is: " + r)

    getStdOut().write("Input information 2:")
    c = getStdIn().readln() // Input: Hello. What's the date today?
    r = c.getOrThrow()
    getStdOut().writeln("The input information 2 is: " + r)

    return
}

Results:

Input information 1: Hello. What day is it today?
The input information 1 is: Hello. What day is it today?
Input information 2: Hello. What's the date today?
The input information 2 is: Hello. What's the date today?