Basthon on the command line
The basthon command runs Basthon's kernels in a terminal, without a browser, with Node.js (version 20.15 or later). It is the same Python (or the same OCaml, C, R…) as in the console and the notebook, with the same modules. It is handy to test an activity before giving it to students, to run it in a script or to mark a set of papers.
Installation
npm install -g @basthon/kernel-nodeUsage
It is used like the python command:
basthon program.py # runs a file
basthon -c "print(6 * 7)" # runs a statement
basthon # opens an interactive consoleThe arguments after the file are given to the program (sys.argv in Python). The interactive console has completion and history, and input() reads the keyboard (or the standard input). In Python, the program reads and writes the files of the computer directly, from the current directory.
The language is chosen from the extension of the file (.py, .sql, .js, .c, .ml, .r) or with the --kernel option (python3 or py, sql, javascript or js, c, ocaml, xcas, r):
basthon hello.c # calls main and returns its exit code
basthon fact.ml # OCaml
basthon --kernel sql # an SQL consoleGraphical outputs
Graphical outputs (Matplotlib figures, tkinter windows, R charts, OCaml or JavaScript canvases, images, HTML…) are shown in a page of the browser, where they stay interactive. The program ends when this page is closed (or the last tkinter window, or with Ctrl+C).
With --no-browser, nothing opens: the images, SVG and HTML shown are saved in a temporary directory, or in the one given by --display-dir.
Options
| Option | Role |
|---|---|
-k, --kernel | the language to use |
-c statement | runs the statement given |
-q, --quiet | does not show the version message of the interactive console |
-v, --verbose | shows the kernel's messages (on the error output) |
--no-browser | does not open the graphical outputs in the browser |
--display-dir directory | where to save the images, SVG and HTML shown |
--no-cache | does not use (nor create) Python's memory snapshot that speeds up its start |
--json | drives the kernel with JSON lines on the standard input and output (for another program) |
-h, --help | shows the help |