Solved

How to excute multiple DOS command simultaneously?

Posted on 2001-06-04
7
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
Better way to make a string with template variables in java 3 34
java example issue 5 45
Running JavaFX on the Raspberry Pi 27 137
What is the use of Forwarding Class in java 1 37
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

733 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