Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Produces empty SVG if stdin is closed #93

Open
nmattia opened this issue Feb 21, 2019 · 2 comments
Open

Produces empty SVG if stdin is closed #93

nmattia opened this issue Feb 21, 2019 · 2 comments

Comments

@nmattia
Copy link

nmattia commented Feb 21, 2019

If stdin is closed termtosvg will create a (mostly) empty svg. E.g. running this:

     termtosvg -g 82x19 -c 'echo hello' out.svg

with closed stdin won't produce any frames. Instead one has to do something like this:

     (tail -f /dev/null || true) | termtosvg -g 82x19 -c 'echo hello' out.svg

which will produce an SVG file where we see "hello" being printed.

@nbedos
Copy link
Owner

nbedos commented Mar 2, 2019

When running the first example I get a reasonable output with both bash and zsh (a still frame displaying 'hello')

I wrote a simple script that closes stdin (shown below) but recording it still gives the animation I was expected.
What OS and shell are you using?

(.venv) nico ~/termtosvg/termtosvg $ cat closed_stdin.py 
from sys import stdin
from time import sleep

stdin.close()
for i in range(10):
    print(i)
    sleep(0.1)
(.venv) nico ~/termtosvg/termtosvg $ termtosvg -g 80x19 -c 'python closed_stdin.py' out.svg
Recording started, enter "exit" command or Control-D to end
0
1
2
3
4
5
6
7
8
9
Rendering ended, SVG animation is out.svg

@nmattia
Copy link
Author

nmattia commented Mar 4, 2019

What OS and shell are you using?

$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic

Note that my issue comes from having stdin being closed in the parent process. Here the first command produces a proper svg, the second one produces an empty one:

$ ./result/bin/termtosvg -c 'echo hello'
Recording started, enter "exit" command or Control-D to end
hello
Rendering ended, SVG animation is /tmp/termtosvg_33py0s74.svg
$ : | ./result/bin/termtosvg -c 'echo hello'
Recording started, enter "exit" command or Control-D to end
Rendering ended, SVG animation is /tmp/termtosvg_2dp1mpj2.svg

(note how echo isn't even executed)

Can you try a command by piping nothing into it? e.g. call : and pipe its output to termtosvg via : | termtosvg -c ...?

Note: I doubt this is a very common use case. I'm generating SVGs from commands inside a nix build, where stdin is closed. The workaround mentioned above (with tail -f /dev/null) works OK.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants