-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotIntegration.java
More file actions
35 lines (28 loc) · 1.17 KB
/
BotIntegration.java
File metadata and controls
35 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BotIntegration {
public static String runBot(String input) {
String result = "";
try {
// Path to your Python executable (venv)
String pythonExe = "C:/Users/DEVAM/IdeaProjects/AI Task Manager/.venv/Scripts/python.exe";
// Path to your bot.py
String scriptPath = "C:/Users/DEVAM/IdeaProjects/AI Task Manager/src/bot.py";
// Run python with input as an argument
ProcessBuilder pb = new ProcessBuilder(pythonExe, scriptPath, input);
pb.redirectErrorStream(true);
Process process = pb.start();
// Read Python output
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
result += line + "\n";
}
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return result.trim();
}
}