views:

772

answers:

5

Hi,

My requirement is that i need to run batch file that is present in remote system from local machine. i am having the following code. But it is giving the following error :Path not correct". I have the ip address of the machine, and i have given the batch file as public share and share name is dsc.

ip address of the machine is 16.181.37.28 Share name is "dsc" I am also pasting the code. I know that the path is wrong. Please tell me how can i give the exact path.

/* * 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 16.181.37.28/dsc/StartVisTsDataCenterMySql-log.bat"; Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(command);

}catch (IOException e) { e.printStackTrace(); } } }

A: 

You're running on Windows but using Posix paths separators. Try "cmd /C \\\\16.181.37.28\\dsc\\StartVisTsDataCenterMySql-log.bat".

Mark
A: 

Hi Mark, Thanks for your amswer. I willtry and let you know.

+1  A: 

Are you trying to run the script ON THE REMOTE machine or ON YOUR LOCAL machine? Your approach will read the file from the remote machine but run it on your local.

The usual way to get something running on a remote machine is having a process on the remote machine to run permanently and listen for requests. If a request arrives this process will start your batch file you would like to have run.

Eduard Wirch
A: 

Hi Eduard, can i sample code to run permenently on the remote machine

A: 

You can test whether it works by creating a service:

sc \\16.181.37.28 create StartVisTsDataCenterMySql-Log binPath= "cmd /c \\16.181.37.28\dsc\StartVisTsDataCenterMySql-log.bat"

Then the command to run it is:

"cmd /c sc \\16.181.37.28 stop StartVisTsDataCenterMySql-Log&sc \\16.181.37.28 start StartVisTsDataCenterMySql-Log"

You'll need to be connected to the share as an administrator (or have the credentials saved). Once you've confirmed that works, change to srvany, as you will get an error in the event log and the batch file will only be allowed to run for 30 seconds otherwise.

If that's not the right answer, perhaps you can elaborate on the real requirement, and give some information on whether reimplementing the batch file in Java is a realistic solution.

Mark