Build and run the project executable.
Synopsis
hx run [OPTIONS] [-- <ARGS>...]Description
The run command compiles your project (if needed) and executes the resulting binary. Arguments after -- are passed to your program.
Options
Run Options
--exe <NAME> Run a specific executable
--release Build with optimizations before running
--no-build Skip build step (run existing binary)Compiler Options
--backend <BACKEND> Compiler backend [ghc, bhc]
--target <TARGET> Cross-compilation targetOutput Options
-v, --verbose Show build output
-q, --quiet Suppress hx output, only show program outputExamples
Basic Run
# Build and run the default executable
hx runPass Arguments to Your Program
# Pass arguments after --
hx run -- --help
hx run -- input.txt --output=result.json
hx run -- arg1 arg2 arg3Run Specific Executable
For projects with multiple executables:
# Run a specific executable
hx run --exe my-cli
# With arguments
hx run --exe server -- --port 8080Release Mode
# Build optimized version and run
hx run --releaseSkip Build
# Run without rebuilding (use existing binary)
hx run --no-buildUsing BHC Backend
# Run using the BHC compiler backend
hx run --backend bhcConfiguration
Configure default run behavior in hx.toml:
[run]
default-exe = "my-app" # Default executable to run
args = ["--verbose"] # Default arguments
[build]
release = false # Debug builds by defaultMultiple Executables
If your project defines multiple executables in the .cabal file:
executable my-app
main-is: Main.hs
hs-source-dirs: app
executable my-cli
main-is: CLI.hs
hs-source-dirs: cli
executable my-server
main-is: Server.hs
hs-source-dirs: serverYou can run each with:
hx run --exe my-app
hx run --exe my-cli
hx run --exe my-serverInteractive Programs
For interactive programs that read from stdin:
# Run and allow interactive input
hx run
# Pipe input
echo "input" | hx run
# Redirect from file
hx run < input.txtEnvironment Variables
Environment variables are passed through to your program:
# Set environment variables
MY_VAR=value hx run
# Or export first
export DATABASE_URL="postgres://..."
hx runExit Codes
The exit code from hx run is the exit code of your program, unless there’s a build error:
| Code | Meaning |
|---|---|
| 0 | Program succeeded |
| 1-255 | Program exit code |
| 5 | Build failure (before running) |
See Also
- hx build — Compile without running
- hx test — Run test suite
- hx watch run — Auto-run on file changes