isinteractive

isinteractive() -> Bool

Determine whether Julia is running an interactive session.

Examples

julia> isinteractive()
true
julia> isinteractive()
false

Common examples of its use:

  1. Conditionally execute code in an interactive session:

    if isinteractive()
       println("Running in interactive mode")
    else
       println("Running in non-interactive mode")
    end

    This example checks if Julia is running in an interactive session and executes different code based on the result.

  2. Control behavior based on the session type:

    function greet_user()
       if isinteractive()
           println("Hello, user!")
       else
           println("Welcome, user!")
       end
    end

    The greet_user function provides a different greeting message based on whether Julia is running interactively or not.

  3. Handle user input differently in interactive and non-interactive sessions:
    function process_input(input)
       if isinteractive()
           println("Processing user input:", input)
       else
           println("Processing input:", input)
       end
    end

    In this example, the process_input function handles user input differently based on the session type.

Common mistake example:

julia> if isinteractive
           println("Running in interactive mode")
       else
           println("Running in non-interactive mode")
       end
Running in interactive mode

In this example, the mistake is missing parentheses after isinteractive. The correct usage is isinteractive(), with parentheses to call the function and retrieve the result.

See Also

BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: