Add execute external program magic. - #78
Conversation
|
@frankfliu great work, and someone has used it to create their own artifact and used it in a notebook, see https://twitter.com/theNeomatrix369/status/1199963064679968769 |
|
Hello! I was wondering why this has not been merged. I tried the code in src/main/java/io/github/spencerpark/ijava/magics/ExecMagics.java from commit 42ea416. It works but the process hangs instead of terminating. I tried the code below with jdk-14 in Windows 10 with IJava. It converts a jupyter notebook called "learning java.ipynb" in the current directory into a jshell script. import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Scanner;
public class ExecMagics {
public void exec(List<String> args) throws Exception {
ProcessBuilder pb = new ProcessBuilder();
pb.command(args);
pb.redirectErrorStream(true);
Process process = pb.start();
try (Scanner scanner = new Scanner(process.getInputStream(), StandardCharsets.UTF_8)) {
while (scanner.hasNext()) {
System.out.println(scanner.nextLine());
}
}
}
}
ExecMagics ex = new ExecMagics();
List<String> cmd = new ArrayList<String>();
cmd.add("cmd");
cmd.add("/k");
cmd.add("jupyter-nbconvert --to script");
cmd.add("./learning_java.ipynb");
ex.exec(cmd);Note: I am a total newbie in java 🙈 |
|
I am an idiot... I was using the wrong command option. If I use |
|
Agreed with above - would be nice if this was merged in to master (main). are there any blockers? |
Add a magic that allow user to execute external program in jupyter notebook.
Example:
%system ls -la