New ScreenPanel
This commit is contained in:
39
plugins/PythonInteractive.java
Executable file
39
plugins/PythonInteractive.java
Executable file
@@ -0,0 +1,39 @@
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PythonInteractive {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProcessBuilder builder = new ProcessBuilder("python", "-i");
|
||||
builder.redirectErrorStream(true);
|
||||
Process p = builder.start();
|
||||
|
||||
PrintStream printStream = new PrintStream(p.getOutputStream(), true);
|
||||
new Thread(() -> {
|
||||
int r;
|
||||
try {
|
||||
while (p.isAlive()) {
|
||||
|
||||
while (p.getInputStream().available() > 0) {
|
||||
r = p.getInputStream().read();
|
||||
System.out.print(Character.toString((char) r));
|
||||
}
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.err.println(ex);
|
||||
}
|
||||
}).start();
|
||||
|
||||
Thread.sleep(200);
|
||||
String cmd = "print (1+2)";
|
||||
System.out.println(cmd);
|
||||
printStream.println(cmd);
|
||||
Thread.sleep(200);
|
||||
p.destroy();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user