Hi All,
i want to run shell script from java.shell script run successfully and generate a file.
But when i want to check the existence of that file,it shows that the file is not present.
please help me to check the file from java or how could i know the proccess(Shell script) is finished.
i have given my code below.
package com;
import java.io.*;
import java.util.*;
public class ScriptBuilder {
public ScriptBuilder() {
}
public void writeScript() throws java.io.IOException {
Runtime rt = Runtime.getRuntime();
rt.exec("chmod 777 testinglinux.sh");
Process p = rt.exec("./testinglinux.sh");
try {
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
String shellfilename = "testing.txt";
if (new File(shellfilename).exists()) {
System.out.println(shellfilename+" File exists");
}
}
public static void main(String[] args) throws java.io.IOException {
ScriptBuilder sb = new ScriptBuilder();
sb.writeScript();
}
}
Thanks!
Vaskar