Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Execute rebol from java

From: nitsch-lists:netcologne at: 3-Jan-2002 18:39

RE: [REBOL] Execute rebol from java Hi Anton [arolls--idatam--com--au] wrote:
> Does anyone have any java code to execute a rebol script? > > I am having serious withdrawal symptoms today. > I am forced to use java at work here, and I just came across > a problem that would have been short, elegant and simple in > rebol, and almost downright impossible in java (it seems). > > I was advised by a more experienced programmer here on > all the benefits of adding three more classes, when all I > wanted to do was navigate a simple array/block with a known > structure and get some strings out. > (Gnashing of teeth.) > > Sorry, I will try to deal with it. > > I am going to go looking for a nice parser for java (if there is > one). >
reviseted java a bit. javacc, coco are compiler-compilers, similar to parse. also there are regular-expressions somewhere near the jpython (and inbuild in 1.4 or that?). to use rebol, below is some playing which starts a rebol-script and fills its output in a vector of lines. but '\n' as line-delemiter is hardcoded, forgot the name for the second windows-char.. hope it helps a bit.
> Anton.
-Volker
> --
[ REBOL [title: {do me to build files..}] make-dir/deep %callrebol-project/volker/callrebol/ WRITE %callrebol-project/callreboldemo.r {rebol[title: file: %callreboldemo.r ] inform layout[ button "send"[hide-popup print ta/text] ta: area "Hello Java!" ] } WRITE %callrebol-project/CallRebolDemo.java { import volker.callrebol.RebolConnection; import java.io.IOException; /** * Demonstrate use of package volker.callrebol. * * @author volker * @version 0.1 */ public class CallRebolDemo { // instance variables static RebolConnection rebolConnection; /** * Constructor for objects of class Demo */ public CallRebolDemo() { // initialise instance variables } /** * the Demo starts here * * @param args command line */ public static void main(String[] args) throws IOException { // put your code here rebolConnection = new RebolConnection(); /*my ide start in the ".."-directory, so "callrebol-project" points ot the root-package with volker.callrebol in it. ugh. configuring around..*/ rebolConnection.scriptAndArguments ="callrebol-project/callreboldemo.r"; rebolConnection.runRebol(); rebolConnection.readAll(); System.out.println(rebolConnection.output.toString()); System.exit(0); } } } WRITE %callrebol-project/volker/callrebol/RebolConnection.java {package volker.callrebol; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Vector; /** * Call a rebol-job, return console-output. * * @author Volker * @version 0.1 */ public class RebolConnection { //parameter variables /**set script and arguments for command-line*/ public String scriptAndArguments; /**here is the script-output, parsed into lines*/ public final Vector output=new Vector(); /**change to point to your rebol*/ public String executable="/usr/local/bin/rebol"; // instance variables Process rebolProcess; Runtime runtime=Runtime.getRuntime(); InputStream inputStream; StringBuffer stringBuffer=new StringBuffer(); /** * Constructor for objects of class RebolConnection */ public RebolConnection() { } /** * Start rebol based on args in public variables. * **/ public void runRebol() throws IOException { rebolProcess = runtime.exec( new String[]{executable,scriptAndArguments}); inputStream = rebolProcess.getInputStream(); } /** * parse the input into lines and fill them in this.output. * can run in another thread. * attention, lines-delemiter is coded platform-dependent, * and needed as last char in file. * * @param input an input stream **/ public void readAll() throws IOException { InputStream input=this.inputStream; int got; while(-1 != (got=input.read())){ if('\n'==(char)got){ String s = stringBuffer.toString(); stringBuffer.setLength(0); output.add(s); } else{stringBuffer.append((char)got);} } } } } ]