Facility Control

 View Only
  • 1.  send to stdin with runtime.exec

    Posted 06-24-2021 01:24
    I am trying to run a python script with runtime.exec within a custom panel.

    var runtime = java.lang.Runtime.getRuntime();
    var args = ["python", "myscript.py"];
    var process = runtime.exec(args);

    How can I then send something to stdin?

    I tried process.getOutputStream().write('text') but it didn't work.

    ------------------------------
    Joseph Adams
    ------------------------------


  • 2.  RE: send to stdin with runtime.exec

    Posted 06-24-2021 09:19
    Hi Joseph
    You are on the right track but the OutputStream you get from the Process object does not have a write method that takes a String as an argument.
    You should be able to take the OutputStream and use it with a MessageBuilder to handle the conversion from String to byte array.

    var output = ogscript.createMessageBuilder();
    output.setOutputStream(process.getOutputStream());
    output.writeString('text');​


    Cheers
    James

    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 3.  RE: send to stdin with runtime.exec

    Posted 06-24-2021 09:35
    Thanks, James!

    ------------------------------
    Joseph Adams
    Fellowship Church Greenville
    ------------------------------