I'm trying to run gcc via ProcessBuilder, but it says: 'gcc' is not recognized as an internal or external command, operable program or batch file.
But running gcc via cmd works.
Here is code:
public static void main(String[] args) {
String command = "gcc C:\\Users\\pawel\\Desktop\\CFG-master\\test.c";
System.out.println(executeCommand(command));
}
public static String executeCommand(String command) {
String line;
String result = "";
try {
ProcessBuilder builder;
builder = new ProcessBuilder("cmd.exe", "/c", command);
builder.directory(new File("C:\\Users\\pawel"));
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (true) {
line = r.readLine();
if (line == null) {
break;
}
result += line + "\n";
}
} catch (IOException e) {
System.out.println("Exception = " + e.getMessage());
}
return result;
}