views:

89

answers:

2

I want to execute a bat file located remotely on server \\testserver\someFolderName\test.bat. I am using process builder and wanted to chande the directory with procbuilder.directory(....), but could not succeed.

Any help is appreciated. Thanks

+1  A: 

In the past I've done it quick and dirty with PSExec

Just start that from your program as its own process with the required arguments to gain access to the batch on the remote computer.

Andrew
A: 

I don't think you can do UNC paths for the ProcessBuilder, but it doesn't really matter in any case.

To run a .bat file, you need to run a windows command shell and have that execute the .bat file, and the command shell doesn't support UNC paths... The way around it is to run your command like this:

cmd.exe /C "pushd \\testserver\someFolderName && test.bat && popd"

Essentially, you're telling the cmd prompt to mount your remote folder as a temporary drive (pushd \testserver\someFolderName), run test.bat and then unmount the temporary drive (popd).

Riaan Cornelius
is code like this:String[] command = { "CMD", "/C", "pushd \\\\testserver\\someFolderName ProcessBuilder probuilder = new ProcessBuilder(command);
String[] command = { "cmd.exe", "/C", "pushd \\\\testserver\\someFolderName ProcessBuilder probuilder = new ProcessBuilder(command);I tried this but couldn't make it work.
This doesnot work. It executes on the same localhost.
Your question was unclear (To me at any rate). I thought you wanted to run the remotely located .bat file locally. Andrew's answer would be more relevant then.
Riaan Cornelius