0

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.

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();
        }
    }

}

How can I develop connection with the remote machine? I just have the IP address of the remote machine.

5 Answers 5

1

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.

0

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.

0

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.

0

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.

0

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

Your Answer

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