D
David Kensche
Hello,
I want to execute an application from within java. Namely an
implementation of GNU patch. Whereas the following code works
fine on Win2k the Process won't stop on WinXP. On both systems
I have installed the patch.exe in the same directory and added
this directory to the PATH variable.
Does anyone know about special pitfalls on XP regarding
Runtime.exec?
Thanks beforehand,
David
/**
* Patch is given as input via stdin whereas the original is given as
* a temporary file is used as target file.
*/
public synchronized String applyPatch(String orig, PatchScript patch)
throws PatchFailedException {
String revString = null;
try {
logger.debug("Write original to a file.");
File origFile = new File(ORIG_FILE_NAME);
if(!origFile.exists()) origFile.createNewFile();
FileWriter writer = new FileWriter(origFile);
writer.write(orig);
writer.close();
logger.debug(origFile.getAbsolutePath() + " written. File closed.");
logger.debug("Start 'patch' process reading original from temp
file '" + ORIG_FILE_NAME +
"' and patch script from stdin '-'.");
logger.debug("patch =\n" + patch);
Process patchProc = Runtime.getRuntime().exec("patch " +
origFile.getAbsolutePath());
logger.debug("Read patch output from streams.");
new MonitorInputStreamThread(patchProc.getErrorStream()).start();
new MonitorInputStreamThread(patchProc.getInputStream()).start();
logger.debug("Write patch to stdin.");
new WriterThread(patchProc, patch.toString()).start();
logger.debug("Wait for 'patch' to finish.");
logger.debug("patch-status="+patchProc.waitFor());
logger.debug("Reading result.");
BufferedReader reader = new BufferedReader(new FileReader(origFile));
String line = reader.readLine();
if(line != null) revString = line + "\n";
while ((line = reader.readLine()) != null) revString += line + "\n";
reader.close();
logger.debug("patched:\n"+revString);
origFile.delete();
} catch(Exception e) {
throw new PatchFailedException("Could not execute patch script!", e);
}
return revString;
}
I want to execute an application from within java. Namely an
implementation of GNU patch. Whereas the following code works
fine on Win2k the Process won't stop on WinXP. On both systems
I have installed the patch.exe in the same directory and added
this directory to the PATH variable.
Does anyone know about special pitfalls on XP regarding
Runtime.exec?
Thanks beforehand,
David
/**
* Patch is given as input via stdin whereas the original is given as
* a temporary file is used as target file.
*/
public synchronized String applyPatch(String orig, PatchScript patch)
throws PatchFailedException {
String revString = null;
try {
logger.debug("Write original to a file.");
File origFile = new File(ORIG_FILE_NAME);
if(!origFile.exists()) origFile.createNewFile();
FileWriter writer = new FileWriter(origFile);
writer.write(orig);
writer.close();
logger.debug(origFile.getAbsolutePath() + " written. File closed.");
logger.debug("Start 'patch' process reading original from temp
file '" + ORIG_FILE_NAME +
"' and patch script from stdin '-'.");
logger.debug("patch =\n" + patch);
Process patchProc = Runtime.getRuntime().exec("patch " +
origFile.getAbsolutePath());
logger.debug("Read patch output from streams.");
new MonitorInputStreamThread(patchProc.getErrorStream()).start();
new MonitorInputStreamThread(patchProc.getInputStream()).start();
logger.debug("Write patch to stdin.");
new WriterThread(patchProc, patch.toString()).start();
logger.debug("Wait for 'patch' to finish.");
logger.debug("patch-status="+patchProc.waitFor());
logger.debug("Reading result.");
BufferedReader reader = new BufferedReader(new FileReader(origFile));
String line = reader.readLine();
if(line != null) revString = line + "\n";
while ((line = reader.readLine()) != null) revString += line + "\n";
reader.close();
logger.debug("patched:\n"+revString);
origFile.delete();
} catch(Exception e) {
throw new PatchFailedException("Could not execute patch script!", e);
}
return revString;
}