Run commands remotely
Run a command in a workspace with hart exec.
hart exec runs a command in a workspace from your computer or a pipeline, without opening a
terminal. It is the tool for a database migration, a one-off script or a quick look at a file.
Run a command
hart exec -w 42 -- npm run migrateThe command runs with bash in /data/app of the workspace, with the workspace's env vars, as the workspace's user.
Its output comes back on your stdout and stderr, and hart exits with the command's own exit status.
Everything after -- is the command. One argument is run as a shell line, so pipes and && work when you quote it:
hart exec -w 42 -- 'ls -la && du -sh node_modules'Several arguments are quoted word by word and run as one command.
Limits
| Run time | 120 seconds by default; --timeout up to 300 |
| Output | at most 1 MiB per stream |
| Exit status | the command's own; 124 when the timeout killed it, 137 when it was killed otherwise |
| Needs | the Editor role on the workspace |
The workspace wakes if it sleeps, and a running command keeps it awake. For anything longer than 5 minutes, open a terminal in the IDE and a keep-awake window.
Use it in a script
set -e
hart exec -w "$WORKSPACE" --timeout 300 -- npm run migrate
hart run-o json prints the output and the exit code as JSON. Exit codes 2 to 6 come from hart itself (usage, sign-in,
permissions, not found, conflict) before the command ran; see Exit codes.
Pull the code first
A pipeline that pushed new commits can bring the workspace up to date before it runs anything:
hart ws wake 42 --wait
hart git pull -w 42
hart exec -w 42 -- npm cihart git pull fast-forwards /data/app; it never merges.