Solved

How to excute multiple DOS command simultaneously?

Posted on 2001-06-04
7
214 Views
Last Modified: 2011-10-03
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.


0
Comment
Question by:UTEK
  • 3
  • 2
  • 2
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6155536
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.
0
 
LVL 2

Expert Comment

by:mariuso
ID: 6155584
What about using OLE automation ? It's nicer don't you think so ?
0
 
LVL 2

Expert Comment

by:mariuso
ID: 6155595
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 ?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:UTEK
ID: 6156050
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.

0
 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 6157967
> Yes, Windows opens a new instance of Word,
> two seperate Word windows.

Two windows yes, but probably open from the one Word  process?
Have a look at the Task Manager, and see if Word is running once or twice.

Another test would be to first open word, and then run your application. Now open a document.

0
 

Author Comment

by:UTEK
ID: 6165286
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 6165973
Thanks for the points :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question