0

I wrote a command-line utility and I want to develop a GUI for it. I saw that almost every tool on linux comes command-line, and it eventually has a GUI which interacts with the command line utility making life easier for those who aren't familiar with command-line.

I want to do something similar, what is the standard in linux to do so?

I thought of two possible solutions:

  1. Create a GUI that simply spawns command-line utility processes, with some arguments to do the required task and wait for it to finish and update the GUI with the results
  2. Implement some kind of server in the command line utility that the GUI can use to gather informations and display them to the user

Is there a standard in linux for linking GUIs to command line utilities?

If yes, what is it?

6

What's most favorably looked upon I think is to actually write SweetApp and libsweetapp together, with the SweetApp commandline application a full-featured but minimalist CLI wrapper around the library. Then, the graphical GSweetApp or KSweetApp uses that lib to build out the GUI application.

Beyond that, there is no authoritative standard and ultimately whatever gets the job done for people is all that matters. What I described and both of your possible solutions are all commonplace.

2

I can't give you representative examples of widely used applications with GUIs and CLIs but as a general rule of good architecture, your program logic should be decoupled from the user interaction logic. Even if you only intend to provide a single user interface, this kind of modularity will still be very valuable for unit testing.

The details might depend on the kind of application but the cleanest solution seems to be to put all the program logic into a library that is then used (linked to) by your CLI and GUI application. Note how this also opens up the opportunity for using your tool without any user interface as a library.

However, if your tool is pretty simple and you would find yourself more comfortable coding the GUI in another language than the CLI application, it could be preferable to simply write the GUI as a wrapper script around the CLI. This has some disadvantages though, as the communication between the processes requires that all parameters be properly marshelled and unmarshalled to / from text and communicating errors between the processes is generally more complicated. Some CLI programs therefore offer special flags that make them accept / produce input / output in a format that is more appropriate for machine processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.