[GH-ISSUE #255] Output recording to stdout #796

Closed
opened 2026-03-15 10:30:06 +03:00 by kerem · 10 comments
Owner

Originally created by @sindresorhus on GitHub (Dec 29, 2017).
Original GitHub issue: https://github.com/asciinema/asciinema/issues/255

Would be useful if asciinema had a flag to output the recording to stdout. This would make it easy to use the recording with other tools without having to write and then read a temp file.

This is what I currently have to do:

temp_file=$(mktemp); asciinema rec $temp_file --command="node example.js" --quiet; cat $temp_file | svg-term --out=screenshot.svg

This is how I'd like to use it:

asciinema rec --command="node example.js" --stdout --quiet | svg-term --out=screenshot.svg

Or just output to stdout if no filename is given.

This is the tool I'm using with asciinema: https://github.com/marionebl/svg-term-cli

// @marionebl

Originally created by @sindresorhus on GitHub (Dec 29, 2017). Original GitHub issue: https://github.com/asciinema/asciinema/issues/255 Would be useful if `asciinema` had a flag to output the recording to stdout. This would make it easy to use the recording with other tools without having to write and then read a temp file. This is what I currently have to do: ``` temp_file=$(mktemp); asciinema rec $temp_file --command="node example.js" --quiet; cat $temp_file | svg-term --out=screenshot.svg ``` This is how I'd like to use it: ``` asciinema rec --command="node example.js" --stdout --quiet | svg-term --out=screenshot.svg ``` Or just output to stdout if no filename is given. This is the tool I'm using with `asciinema`: https://github.com/marionebl/svg-term-cli // @marionebl
kerem closed this issue 2026-03-15 10:30:11 +03:00
Author
Owner

@ku1ik commented on GitHub (Apr 5, 2018):

If you redirected asciinema rec's stdout to a pipe then you wouldn't see what you're doing in your terminal ;) The stdout has to go directly to terminal emulator, without any redirects/captures. In other words it's impossible to achieve it with pipe.

But you can try this (works in bash, and probably in zsh too):

asciinema rec -c "node example.js" >(svg-term --out=screenshot.svg)

>(some command) runs some command in a subshell, creates a file (pipe) at /dev/fd/... which is connected to this command's stdin, and then the whole >(...) expression is replaced with /dev/fd/... path :)

I did it with wc -l, which counted lines of the resulting recording, printing 27:

bash-3.2$ asciinema rec >(wc -l)
asciinema: recording asciicast to /dev/fd/63
asciinema: press <ctrl-d> or type "exit" when you're done
bash-3.2$
...
...
bash-3.2$ exit
asciinema: recording finished
asciinema: asciicast saved to /dev/fd/63
      27
<!-- gh-comment-id:379056717 --> @ku1ik commented on GitHub (Apr 5, 2018): ~~If you redirected `asciinema rec`'s stdout to a pipe then you wouldn't see what you're doing in your terminal ;) The stdout has to go directly to terminal emulator, without any redirects/captures. In other words it's impossible to achieve it with pipe.~~ But you can try this (works in bash, and probably in zsh too): asciinema rec -c "node example.js" >(svg-term --out=screenshot.svg) `>(some command)` runs `some command` in a subshell, creates a file (pipe) at `/dev/fd/...` which is connected to this command's stdin, and then the whole `>(...)` expression is replaced with `/dev/fd/...` path :) I did it with `wc -l`, which counted lines of the resulting recording, printing `27`: ``` bash-3.2$ asciinema rec >(wc -l) asciinema: recording asciicast to /dev/fd/63 asciinema: press <ctrl-d> or type "exit" when you're done bash-3.2$ ... ... bash-3.2$ exit asciinema: recording finished asciinema: asciicast saved to /dev/fd/63 27 ```
Author
Owner

@chewi commented on GitHub (Dec 19, 2018):

I tried the >() approach but it doesn't work now. It complains of an illegal seek.

<!-- gh-comment-id:448536195 --> @chewi commented on GitHub (Dec 19, 2018): I tried the `>()` approach but it doesn't work now. It complains of an illegal seek.
Author
Owner

@ku1ik commented on GitHub (Dec 19, 2018):

That is an advanced bash trick, so it may not work in all cases.

<!-- gh-comment-id:448558396 --> @ku1ik commented on GitHub (Dec 19, 2018): That is an advanced bash trick, so it may not work in all cases.
Author
Owner

@glaudiston commented on GitHub (Dec 3, 2020):

Have you tried with echo and jq in bash ?:

echo -e "$(cat your-asciinema.json | jq '.stdout[][1]' | tr -d '"\n\r')" 
<!-- gh-comment-id:738012869 --> @glaudiston commented on GitHub (Dec 3, 2020): Have you tried with `echo` and `jq` in bash ?: ``` echo -e "$(cat your-asciinema.json | jq '.stdout[][1]' | tr -d '"\n\r')" ```
Author
Owner

@ku1ik commented on GitHub (Feb 20, 2022):

The improvements from https://github.com/asciinema/asciinema/pull/473 make it possible to do this:

asciinema rec --command="node example.js" --quiet /dev/stdout | svg-term --out=screenshot.svg

This will be released in v2.2.

<!-- gh-comment-id:1046265041 --> @ku1ik commented on GitHub (Feb 20, 2022): The improvements from https://github.com/asciinema/asciinema/pull/473 make it possible to do this: ```bash asciinema rec --command="node example.js" --quiet /dev/stdout | svg-term --out=screenshot.svg ``` This will be released in v2.2.
Author
Owner

@ku1ik commented on GitHub (Apr 28, 2022):

Also I just merged #492 which allows use of - as the filename representing stdout, then piping the output to another tool:

sciinema rec --command="node example.js" - | svg-term --out=screenshot.svg
<!-- gh-comment-id:1112618448 --> @ku1ik commented on GitHub (Apr 28, 2022): Also I just merged #492 which allows use of `-` as the filename representing stdout, then piping the output to another tool: ``` sciinema rec --command="node example.js" - | svg-term --out=screenshot.svg ```
Author
Owner

@sashaaro commented on GitHub (May 12, 2022):

@sickill can you implement read terminal stdout steam via pipe without specify and run command

bash -c "./install.sh" | asciinema rec "install.cast"

actually I need it for use pipe programmly while write extension for https://github.com/vercel/hyper
idea in background run asciinema and forward stream to asciinema like

var child = require('child_process');
var asciinemaProc = child.spawn('asciinema rec ...');

hyperTerminalStream.stdout.pipe(asciinemaProc.stdin, { end: false });
<!-- gh-comment-id:1125466927 --> @sashaaro commented on GitHub (May 12, 2022): @sickill can you implement read terminal stdout steam via pipe without specify and run command ```bash bash -c "./install.sh" | asciinema rec "install.cast" ``` actually I need it for use pipe programmly while write extension for https://github.com/vercel/hyper idea in background run asciinema and forward stream to asciinema like ```js var child = require('child_process'); var asciinemaProc = child.spawn('asciinema rec ...'); hyperTerminalStream.stdout.pipe(asciinemaProc.stdin, { end: false }); ```
Author
Owner

@ku1ik commented on GitHub (May 17, 2022):

@sashaaro You can do it the other way around:

asciinema rec -c ./install.sh install.cast

Or if you explicitly want bash to execute the script (in case the script doesn't have shebang line):

asciinema rec -c "bash -c ./install.sh" install.cast
<!-- gh-comment-id:1128830356 --> @ku1ik commented on GitHub (May 17, 2022): @sashaaro You can do it the other way around: ```bash asciinema rec -c ./install.sh install.cast ``` Or if you explicitly want bash to execute the script (in case the script doesn't have shebang line): ```bash asciinema rec -c "bash -c ./install.sh" install.cast ```
Author
Owner

@ku1ik commented on GitHub (May 17, 2022):

Closing this as support to record to stdout (by specifying - as output filename) was added in 2.2.0.

<!-- gh-comment-id:1128830928 --> @ku1ik commented on GitHub (May 17, 2022): Closing this as support to record to stdout (by specifying `-` as output filename) was added in 2.2.0.
Author
Owner

@sashaaro commented on GitHub (May 17, 2022):

@sickill unfortunately https://hyper.is/ plugins api does not allow to replace shell, hyper run shell command himself. I need run asciinema in backround separately and have method to send termianl stream to asciinema. Lets do asciinema just receive terminal stream via stdin pipe

<!-- gh-comment-id:1129145006 --> @sashaaro commented on GitHub (May 17, 2022): @sickill unfortunately https://hyper.is/ plugins api does not allow to replace shell, hyper run shell command himself. I need run asciinema in backround separately and have method to send termianl stream to asciinema. Lets do asciinema just receive terminal stream via stdin pipe
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asciinema#796
No description provided.