Welcome to PlantUML Q&A, where you can ask questions and receive answers from other members of the community.

You can also submit new features request and vote for them.

How to start generating picture with pipe mode

0 votes
Hello,

I'm trying to use plantuml "-pipe" parameter to start plantuml only once for generation of many pictures.

But it seems that the generation only takes place if stdin is getting closed. This means I have to start

plantuml again which costs time. Is there a possibility to let plantuml run once and to put one picture description

via stdin after another with getting one picture after another via stdout (with apropriate separator)?

With kind regards,

Stefan
asked Mar 19 by anonymous

1 Answer

0 votes
We've just published a new beta https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0

This beta should better handle the -pipe option : you can now send several diagrams in stdin (please use appropriate @startXXX / @endXXX delimitor for those diagrams).

Right now, there are no delimitor between pictures in stdout : you have to detect PNG header start : is it possible for you ?

In the future, we may add some optional delimitor (using for example a -delimitor flag) in the command line.

This has not been widely tested, so please feedback if you find issues!

Thanks

PS: Note that you could also use the FTP option to generate several diagrams without having to restart java process. See http://plantuml.sourceforge.net/qa/?qa=5694/c%23-plantuml-jar-alternative
answered Mar 19 by plantuml (118,230 points)
Hello,
thanks for the answer. I will try the FTP mode soon.
With the new version the behavior of the -pipe mode is the same.
As long as I not close the pipe plantuml is not generating any picture.
To eliminate any problem with the PNG output I set the output format
to -ttxt. With the -verbose parameter I get the start information, but
no pictures. Is there another way to dig it down?

With kind regards,
Stefan
We've made some change in the newest beta (beta 4)
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0
Could you try it ?
(And send us the output of -verbose if it does not work better)
Try also to send many diagrams (1000?) to the input stream to see if the generation starts before pipe close.
Thanks
This one I tested. My problem is, that my test is in the form that I start
a process from within emacs (on windows, same on Linux) in an comint buffer and then send via
comint-send a diagram. But the comint buffer does not show the result.

Example:
(progn
  (apply 'make-comint "plantuml" "java" nil '("-jar" "plantuml.jar" "-pipe" "-tutxt" "-verbose"))
  (delete-other-windows)
  (switch-to-buffer-other-window "*plantuml*")
  (other-window -1))

(comint-send-string (get-buffer-process "*plantuml*") "@startuml\n Alice -> Bob\n @enduml\n")

Results in the *plantuml* buffer:
(0.000 - 243 Mo) 238 Mo - PlantUML Version 2017.08beta3
(0.020 - 243 Mo) 238 Mo - GraphicsEnvironment.isHeadless() false

But not more if evaluating the comint-send-string.

To check the result I tried:
(progn
  (apply 'make-comint "cmd" "cmd" nil '())
  (delete-other-windows)
  (switch-to-buffer-other-window "*cmd*")
  (other-window -1))

(comint-send-string (get-buffer-process "*cmd*") "dir\n")

which works flawlessly sending the dir output to the *cmd* buffer.
I tried it also on Linux with the same negative result, so I'm convinced
that this is no problem of windows.

Is there a possibility to give more debug output?
Could you test with beta 4 ?
(The logs says PlantUML Version 2017.08beta3 )
Thanks!
I tested on Linux (can do the same tomorrow on Windows) with beta5 same way as described above, gives:

(0.000 - 240 Mo) 234 Mo - PlantUML Version 2017.08beta5
(0.025 - 240 Mo) 234 Mo - GraphicsEnvironment.isHeadless() false
(0.099 - 240 Mo) 233 Mo - managePipe::before readOneDiagram
(5.707 - 240 Mo) 233 Mo - one line read:@startuml

(5.709 - 240 Mo) 233 Mo - one line read: Alice -> Bob

(5.709 - 240 Mo) 233 Mo - one line read: @enduml

But no diagram output.

With kind regards,
Stefan
There seems to be an extra space between : and @ in
(5.709 - 240 Mo) 233 Mo - one line read: @enduml
Can you double check that there are no space before @enduml ?
Thanks
Oh damn,... that's it.
Thank you for your patience and quick help.
I will try it tomorrow on Windows.

Now it is the time to ask if it would be possible to implement the "-delimitor" flag, so that I can define the delimiter which comes directly after the generated picture.

With kind regards,
Stefan
Great! That's nice!
So we've just built a new beta (beta6) https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0

In this beta, we have slightly changed some code about pipe reading (basically because the previous beta were not dealing the charset).
So if there is a regression with -pipe option please tell use.

We have also added a -pipedelimitor flag, so that you can do:
java -jar plantuml.jar -pipe -pipedelimitor XXXXXXXXX

Tell us tomorrow if it matches your need!
Thanks. Looks nearly good. Would it be possible to print the delimitor in time directly at the end of the generated picture, then I can use it as the end marker of the generation. It seems that you print it only before outputting the next picture.

With kind regards,
Stefan
Ok, beta7 should do the job
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0
Feedback welcome!
Thanks for all. This works like expected under Windows. I will now
try to but all the pieces together for what I want.
Thanks very much.
With kind regards,
Stefan
Hello again,
I tried some things and there is sadly one more problem:
For my plan I send nearly every keystroke via pipe to plantuml, so they script is not syntactically correct some times. In this situation I get:
     ┌─┐          ┌─┐
     │A│          │B│
     └┬┘          └┬┘
      │            │
      │───────────>│
     ┌┴┐          ┌┴┐
     │A│          │B│
     └─┘          └─┘
===END-OF===
.. (skipping 9 lines) ...
                          
A -> B                    
                          
E                         
^                         
 Syntax error: E          
===END-OF===
ERROR
12
Syntax error: E

In this example, same as if using -tpng, I sent a correct description,
-pipedelimiter is "===END-OF===", and afterwards a false one.

In this situation the error is given as text, which is a picture with -tpng. But after the delimiter I get additional text which is necessary for
telling the user where the error is, but it comes after the delimiter.

Would it be possible to:
- have the delimiter at the end of all
- the error description as picture (for tools which need this)
- and an additional error message in ascci, as if using -tutxt,
  which would it make simpler to show the user the previous picture
 and an error message as overlay right in the source.
Perhaps an the mechanism of the delimiter can be changed to have
an real end marker and perhaps a separator of the parts of the answer.

I hope I have clearly written down my problem, looking forward for
an answer.

With kind regards,
Stefan
Do not worry about iterative development : this is usually how we work.

Firstly, diagrams images (PNG or ASCII) are sent to Standard Ouput and error message are sent to Error Ouput, so there should not need to separate them (they are not in the same flow).
Printing information to Error Ouput was useful when only one diagram was generated.
I've got the feeling that you are using PlantUML in some daemon mode here, to printing information to Error Ouput maybe make no sense.

So in last beta, we decided to remove any flow to Error Ouput when -pipedelimitor is used. Note that this is not a final decision, just a try.
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0

Does it make it easier to use for you ?
Thanks. I think your decision is right. I'm stuck right now with displaying the png result inside of emacs. When I have solved that problem I will take a closer look in how to show error messages.

So far, thanks.
With kind regards,
Stefan
I made progress and am able to show the generated picture inside of emacs (was a conversion problem of the generated output). Now I would like to address an additional feature request.

If the user is typing the description of a picture it will contain errors, because I send the typed text after nearly every typed char to plantuml. What I need now is the possibility to scan this error to show the error hint in the typed text while showing the last correct picture.

Would it be possible to get another program parameter which switches the graphical output of the error message into a textual one?

If then the textual error message would contain a line and column number of the error message, like compiler error messages, together
with the error description, I can highlight the typed input text with this.

(If used together with "-pipedelimitor" parameter the textuel description
of the error should end with the delimitor.)

With kind regards,
Stefan
There is a -syntax flag that should do the job
However, when this flag is used, no image is generated : only the syntax is checked. So this may not completely fit your need : you would have to run two instance of PlantUML, one for syntax check, the other for image generation.

I think the better option is to put back text error message that has been recently removed when using -pipedelimitor. Do you agree ?
Hello, I think it is better to just run one instance, because otherwise I have to pipe the data in the two instances simultaneously. So the -syntax is not usefull here.

Adding back text error messages will be good. But they should be detectable and also be delimited at the end.

With kind regards,
Stefan
In last beta (beta14):
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0

We have put back the error text output, now using the delimitor provided by -pipedelimitor (if any)

Note that in the Java code, we do output image to standard flow (stdout in unix notation)
And we do output error message to standard error (strerr in unix notation)
see https://en.wikipedia.org/wiki/Standard_streams

I don't know how you receive those two streams in your case.

Anyway, we are ok to implement some modifications that might help you with your emacs integration
Short try. This is not easy and on windows it will start a pipe process, which, as I remember, has some difficulties. So, if possible, I would like to get the text error on the same stream as the picture, but without the picture in the error case; switched on with an extra parameter.

With kind regards,
Stefan
With last beta (beta15):
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0
There is a new flag -pipeNoStderr that you should use.
It should work the appropriate way. However, this has not really been tested, so do not hesitate to feedback.
Thanks!
Thanks very much, looks good after first try.
With kind regards,
Stefan
Hello, I tested a little bit. Works good. But in case of an error the given line number seems every time to have the doubled value.

With kind regards,
Stefan
Could you give a simple example ? Not sure to understand the meaning of "doubled value". Thanks!!
Sorry for not being precise enough.

Each lineending in the examples is given as 0xah.

@startuml
@enduml

gives:
ERROR
1
Empty description

@startuml
a
@enduml

gives:
ERROR
2
Syntax error: a

@startuml
a -> b
c
@enduml

gives:
ERROR
4
Syntax error: c

@startuml
a -> b
c -> d
e
@enduml

gives:
ERROR
6
Syntax error: e

With kind regards,
Stefan
Ok, thanks for the detail report.
This should be fixed in last beta (beta21)
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0
Thank you, look good.
With kind regards,
Stefan
Support This Project Offer 250 Mo! Follow PlantUML on Twitter
...