1

I am having the sample code like this.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author padmaja
 */

import java.io.*;
class Test{
  public static void main(String arg[]){
    try{
      String command = "cmd /C start C:/excel.bat";
      Runtime rt = Runtime.getRuntime();
      Process pr = rt.exec(command);  
    }catch (IOException e) {
      e.printStackTrace();
    }
  }
}

I am opening excel sheet by using the above code.

The problem is if use a thread to open excel sheet every 15 minutes then multiple excel sheet will be dispalyed. I want to close the running of a batch file from the above code itself.

Thanks in advance

3
  • You should format the code in your snippet. Do this by adding 4 spaces to the beginning of each line. Also, have a blank line above and below the snippet. Commented Jan 12, 2009 at 6:09
  • What do you do in this Excel sheet? Is a VBA macro executed? Do you await any user interaction? Please provide some more details (See Hemal Pandya's answer) Commented Jan 12, 2009 at 8:27
  • The thing is, i find code like this really weird, because it's a symptom indicating a deeper problem of stovepipe application/scripts all glued together using a mess. If its possible, its better to address the problem instead of hacking around a fix like this.Though, it might not be possible i agree Commented Jan 12, 2009 at 9:41

3 Answers 3

2

Once the Excel sheet is opened, the end-user will interact with it, right? How will you know it is ok to close it? If you are only starting Excel for some macros that run on load, you might be able to exit in that macro itself.

Sign up to request clarification or add additional context in comments.

2 Comments

That was my first thought! WHEN do you know, it's the right time to close a sheet? Does a VBA macro works on it? Then this macro should close the file. Never ever speculate about time a process will take.
Very correct. But unless pallavi clarifies we will never know :-)
0

One option is to use taskkill command (http://technet.microsoft.com/en-us/library/bb491009.aspx) to kill the process. Of course this will simply terminate the process so you won't be able to do any cleanup/save etc.

Comments

0

In my project we have the same issue.

You can write an DLL which can open and close started processes as you want it. In C++ you can handle the processes like you described. YOu get a process id where you can identify running processes. As far as i know you can only kill a process, not terminate gracefully by asking the user to close the window.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.