0

I'am looking for a way to open a MS Word application with Java and after user finish to edit opened document with MS Word the process must upload modified file into database.

I have tryed to use Process command and waitFor method but Java is not waiting for the process to finish..

Any other solution? or idea how to do this? example:

public static void main(String[] args) {
        try {
            int exitValue = 0;
            //open MS WORD....
            Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler winword "+filename);
            //wait for a process to finish..
            int i = p.waitFor();
            //upload modified file to database
            upload(...);
            System.out.println(i);
        } catch (IOException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
Ferguson
  • 527
  • 1
  • 11
  • 29

1 Answers1

2

Swing requires that your program construct and manipulate Swing GUI objects only on the event dispatch thread. When the user concludes editing, execute a SwingWorker that handles the upload in your implementation of doInBackground() using ProcessBuilder. Optionally, display diagnostic output from the upload process in a JTextArea. Invoke setProgress() as desired; a listening JProgressBar will update itself accordingly. Mark the file as saved in your implementation of done().

A related example is seen here.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045