tags:

views:

975

answers:

7

Hi,

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

The above code works fine if the batch file is present in local machine.
I need to run the batch file that is present in the remote machine from the above code.
How can I develop connection with the remote machine ?
I just have the IP address of the remote machine.

Please help me. Thanks in advance,

A: 

One possible solution might be to export your Visuals class to an RMI server, and then invoke the method that executes the batch file remotely from a remote client.

Take a look at the Sun RMI Documentation.

David Grant
+1  A: 

If you make the Folder containing the batch file as a Public Share and then use that address of the batch file like "\ComputerName\ShareName\BatchFile", you can access the batch file.

Hope this helps.

Pratheeswaran.R
A: 

Hi Dave Gratn, Can i have example for u r Answer please. How to export visuals class to an RMI server and invoke method.

Regards,

A: 

Take a look at the AT command. According to its documentation:

The AT command schedules commands and programs to run on a computer at a specified time and date. The Schedule service must be running to use the AT command.

So you might be able to do something like:

AT \\123.123.123.123 17:00 cmd /c "C:\test.bat"

If you set the time you want to run it at approximately the current time, your script will run.

Edit: this is what you would run from the command-line. You should put this in your command string.

Ruben Steins
A: 

To update my previous answer, you really need to look at the documentation otherwise it is unlikely you will understand what the code is doing.

David Grant
A: 

Hi RubenSteins,

AT \123.123.123.123 17:00 cmd /c "C:\test.bat" I dint understand where to give the above line. Can u help me

Regards,

A: 

Hi,

I tried AT and it throws a access denied error.

This is also tricky in the sense that it schedules the remote machine to run a task at the specified time.

If the machine clocks are not in synch this could cause trouble.

There should be other alternatives available.

THanks, Manglu