I'm trying to add version control to my web server (on windows, I know...) and I need to use a batch script to do automatic adds and commits. Here is what I have now :
public static void bzr_add(String path, String commit) throws IOException {
ProcessBuilder pb = new ProcessBuilder(scripts + "bzr_add.bat", storage, path, "\"" + commit + "\"");
Process p = pb.start();
String line;
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = r.readLine()) != null) {
System.out.println(line);
}
r.close();
try {
p.waitFor();
} catch (InterruptedException ex) {
Logger.getLogger(local.class.getName()).log(Level.SEVERE, null, ex);
}
}
With "scripts" being the directory where the script can be found, "storage" the storage directory and "path" the path of the new file.
The batch script :
cd %1
bzr add %2
bzr commit -m %3
And what I obtain :
Infos: C:\Program Files\glassfish-3.1.2\glassfish\domains\domain1>cd c:\storage_dir\
Infos: C:\storage_dir>bzr add dir\file.ext
Infos: C:\storage_dir>bzr commit -m "commit_message"
So it seems ok, and when I copy this in the cmd shell it works (it also works when I do bzr_add.bat par1 par2 par3 in the shell). And if I modify the script to create new files, they are created in the correct directory so something is executed correctly.
But bazaar doesn't seem to agree on that when I execute the script through java, any guesses ?
I found the solution to my own question (although I don't know why I needed to do this).
I have to add this line to my batch file :
path = %PATH%;c:\Program Files\Bazaar\
It's weird because it's already in the path when I use cmd.exe, but it works that way. Maybe it will help someone with the same problem.