question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow CLI to read a diagram from stdin and write the result to stdout

See original GitHub issue
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Is your feature request related to a problem? Please describe.

The diagrams.net (Electron-based) CLI is very useful but I would like to read a diagram from stdin and write the output to stdout to avoid file manipulations.

It would be particularly useful when executing the CLI from a program. For instance, let’s say that I want to write a small HTTP service on top of the CLI. I will receive the input diagram as a request body and I want to write the result in the response. In this case, I don’t want to:

  1. write a temporary input file to the disk,
  2. execute the command,
  3. read the generated output file,
  4. delete both the input and output file

It would be more efficient to execute the command with the input file as stdin and to read the result from stdout. No file manipulation.

Describe the solution you’d like

When exporting a single input file to a single output file, we could allow diagrams.net CLI to read it from stdin and output the result to stdout. By convention, command-line interfaces usually use - (dash character), for instance:

cat input.xml | drawio --export --format svg -

The above command will read the diagram from stdin. It’s also common to output to stdout (by default) when the input is read from stdin. In other words, the above command will output to stdout by default, but the following command will output to output.svg:

cat input.xml | drawio --export --format svg --output output.svg -

Similarly, if we want to explicitly output to stdout then we can use the value -:

drawio --export --format svg --output - input.xml

Please note that the value of the parameter output is -.

Describe alternatives you’ve considered

I guess writing my own CLI inspired by electron.js but that would be a maintenance burden.

For reference, I did try to create a simple CLI based on Puppeteer (instead of Electron) but I had to make some changes to export.js in order to be able to call the right functions from Puppeteer (most notably render and get-svg-data callback).

If this is something that you would like to support (i.e., providing both an Electron-based CLI and a Puppeteer-based CLI) then I would gladly help. I know that diagrams.net is closed to contributions but let me know if I can be of any help.

Additional context

I’m working on https://kroki.io and I would like to provide an API to convert diagrams.net XML files to PNG, JPEG or SVG images (and potentially PDF and VSDX). As far as I understand, diagrams.net is using the browser (client-side JavaScript) to convert diagrams to images. So, I’m looking for a self-contained and lightweight solution to provide this service server-side.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:16
  • Comments:5

github_iconTop GitHub Comments

1reaction
davidjgraphcommented, Jan 5, 2022

No, that’s the current server-side generation, it’s just we switched to that new architecture in 2018.

It doesn’t rely on anything external, that is the external server. export3.html just happens to be served externally, it could just as well be bundled on that node sever.

0reactions
davidjgraphcommented, Jan 5, 2022

Yes, that look like the right list (you’ll soon find out if one is missing 😃 ).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Standard Input and Standard Output | Linux Shell - InformIT
The lpr (line printer) utility accepts input from either a file or standard input. When you type the name of a file following...
Read more >
Writing to stdin and reading from stdout (UNIX/LINUX/C ...
I was working on an assignment where a program took a file descriptor as an argument (generally from the parent in an exec...
Read more >
AWS Command line: S3 content from stdin or to stdout - Loige
This article presents a quick tip that will help you deal with the content of files in S3 through the AWS command line...
Read more >
Input Output Redirection in Linux/Unix Examples - Guru99
What is Redirection? Redirection is a feature in Linux such that when executing a command, you can change the standard input/output devices.
Read more >
call it from your script using command line - PlantUML
With this option, a diagram description is received through standard input and the PNG file is generated to standard output. No file is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found