I'm having some problems with a certain segment of my code. What is supposed to happen is that the Java program takes some predetermined variables and uses UNIX's "sed" function to replace the Strings "AAA" and "BBB" in a pre-written shell script. I have three methods to do this: one that replaces the Strings in the file using "sed" and writes the output to a different file; one that removes the original file with the "rm" command; and one that renames the output file to the name of the original file using "mv". There are three copies of the shell script in three different directories, and each one should be replaced with it's own specific variables.
The replacement should occur for all three shell script files, but it only occurs for two. On the third shell script, it seems as if the process did not complete, because the byte size of that file is 0. The file that is not replaced is completely random, so it's not the same file not working during each run.
I'm not sure why this error is occuring. Does anyone have any possible solutions? Here is the code:
public void modifyShellScript(String firstParam, String secondParam, int thirdParam, int fourthParam, String outfileDirectoryPath) throws IOException{
String thirdDammifParamString = "";
String fourthDammifParamString = "";
thirdDammifParamString = Integer.toString(thirdDammifParam);
fourthDammifParamString = Integer.toString(fourthDammifParam);
String[] cmdArray3 = {"/bin/tcsh","-c", "sed -e 's/AAA/"+firstDammifParam+"/' -e 's/BBB/"+secondDammifParam+"/' -e 's/C/"+thirdDammifParamString+"/' -e 's/D/"+fourthDammifParam+"/' "+outfileDirectoryPath+"runDammifScript.sh > "+outfileDirectoryPath+"runDammifScript.sh2"};
Process p;
p = Runtime.getRuntime().exec(cmdArray3);
}
public void removeOriginalShellScript(String outfileDirectoryPath) throws IOException{
String[] removeCmdArray = {"/bin/tcsh", "-c", "rm "+outfileDirectoryPath+"runDammifScript.sh"};
Process p1;
p1 = Runtime.getRuntime().exec(removeCmdArray);
}
public void reconvertOutputScript(String outfileDirectoryPath) throws IOException{
String[] reconvertCmdArray = {"/bin/tcsh","-c","mv "+outfileDirectoryPath+"runDammifScript.sh2 "+outfileDirectoryPath+"runDammifScript.sh"};
Process reconvert;
reconvert = Runtime.getRuntime().exec(reconvertCmdArray);
}