• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Updates to Java GUI when Running UNIX Shell Script

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a kind of install wizard, that I have named JInstall. This JInstall calls a UNIX shell script named install. This script, is the real installation program, and my JInstall is just a nice front end that gathers settings from the user, presents the License.txt file, etc. My JInstall extends JFrame, and uses several JPanels together with a CardLayout Manager to handle the different pages that the user has to go through, for example, a License Agreement Page, Directory Selection Page, and so on.

In the Install Page, I want to display the output from the install shell script in a JTextArea. My problem is that, the output from the shell script install is not simultaneously displayed as the install script runs. All the output is displayed when the script ends, and the scripts takes 1 - 2 minutes to run. Thus, my Java application seams to hang when the user clicks the Install button (a JButton ...).

Please note that my call of the install shell script, is done through the following steps:

runInstallShellScript() {
cardLayout.show( cardPanel, "Install" );
SwingUtilities.invokeLater( this ); // To let the GUI be updated.
}

public void run() {
// Run the install script
}

The use of SwingUtilities.invokeLater is needed, as previously, the updates to the GUI did hang while the install script run. Now, the Install Page is displayed, and then starts the shell script.

So, thus somebody know what I should do? Maybe, there is a complete different approach to have when creating Java-GUI-shell-script-application.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't post nearly enough code to tell you for sure, but I can make some educated guesses. It sounds like a typical Swing threading issue. Which thread invokes the method run()? If you are invoking it from your install button action handler? If so you are hogging the Swing event thread and preventing updates. Do you invoke Process.waitFor()? That method blocks until the new process finishes and would also prevent GUI updates. You probably need to start 3 threads: one to spawn the new process and wait for it to finish and two threads to read from the output and error streams. Those streams have fixed-size buffers and if you don't clear them they can fill and prevent your process from completing. The swing event thread would then be free to make updates to the gui.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manuel --



This is precisely what you don't want to do. By using SwingUtilities.invokeLater(), you're specifically arranging for the install script to be run on the GUI thread, which blocks painting. You want the install script to run on another thread altogether.

Most likely you'd like to have a button press trigger the installation. What that button press should do would look something like



i.e., create a new Thread in which to run the installation, point it at the run() method in "this" object, and start it.

I'm moving this thread to the Swing/AWT forum, as (as Joe says) this is a typical Swing threading question and has nothing to do with Linux/UNIX.
[ July 12, 2004: Message edited by: Ernest Friedman-Hill ]
 
Get me the mayor's office! I need to tell her about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic