Link to home
Start Free TrialLog in
Avatar of UTEK
UTEK

asked on

How to excute multiple DOS command simultaneously?

I have a signed applet. It has couple links to the documents on user's local machine. When user clicks on a link, it creates a new thread and uses DOS "start" command to open the document.  The run method of the thread is something like this:  

public void run()
{
   //Now call up the application to view doc
   try
   {
      //Get Windows information
      System.out.println(System.getProperty("os.name"));
      System.out.println(System.getProperty("os.arch"));
      System.out.println(System.getProperty("os.version"));
     
      //This is NT command
      Runtime.getRuntime().exec("cmd /C \"start /wait
"+defdir+"\"").waitFor();
      System.out.println("Finishing editing - "+defdir);
   }
   catch (Exception e)
   {
      System.out.println(e.getClass.getName());
   }
}

When I opened the first document, it was fine. The document did stay on the screen. When I opened the 2nd document while the 1st one was still up, it did launch the 2nd document in WORD BUT the 2nd thread immediately executes ==> System.out.println("Finishing editing - "+defdir); without waiting the close down of the 2nd document. How come?
Is it because each applet has only one runtime env and it can only execute one dos command at a time? Is there any work around? Or any alternative?

My goal is to launch multiple applications(associated with the files) on the local machine to edit the documents. Once the user finishes editing a doc, the applet determines if the document has been modified. If so, it saves it back to the server.


Avatar of Mick Barry
Mick Barry
Flag of Australia image

It sounds like what's happening is that when you run the command the second time Windows sees that Word is already running so the command simply passes the file to the existing process to open and then exits.
Does the second doc get opened in a new instance of Word or the same.
Not sure of a workaround, it's really a Windows specific question. You could fire up the application directly but that'll introduce lots of other problems.
Avatar of mariuso
mariuso

What about using OLE automation ? It's nicer don't you think so ?
Are you sure, you are creating a new thread, not using the same one ?

If you make
WordCreator x = new WordCreator("a word document");

and on button press

x = new WordCreator("another word document");

the first one is destroyed.

It's this the problem ?
Avatar of UTEK

ASKER

objects:
   Yes, Windows opens a new instance of Word, two seperate Word windows.

mariuso:
   We would like to deploy our applet to both IE and netscape (as many Java enable browser as possible) across Windows, Mac , Unix and Linux. Netscape and other platforms do not support OLE automation, do they? On the other hand, how does Active X control work with Java applet?

Yes, they are running in different thread.
I have a Vector object to store the reference, so even x is assigned to a new reference, the old thread is not destroyed.

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of UTEK

ASKER

objects, thanks for pointing it out. It first starts with 2 Word processes and then finially they merge into one process and kill my 2nd thread....SHOOT.
Thanks for the points :)