Thread: [tcljava-user] Q. How does java interact with tcl?
Brought to you by:
mdejong
From: Kim,Younghun <mys...@ic...> - 2008-06-14 02:52:04
|
Hello dear , First at all, I'm not sure my question is proper or not to this topic. But, I'm considering I should use Tcljava. Because I ask to here. I'm doing a project. In this project I'm making simple java program which can interact with "tclsh". Java program is designed originally without tclblend and jacl. In my idea, java can call the "tclsh" by using 'ProcessBuilder' class. It then gets input/error/ouput-streams of tclsh. If I handle these three-stream, I may be able to handle tclsh through java-program.(sample source code is attached below) This is my idea but, it doesn't work. I think I couldn't get these streams. Anyway while processbuilder are handling tclsh, tclsh process is working on system. I guess tclsh, I guess this is a kind of shell, uses own shell, so java cannot intercept IO streams of it. How do you think of this problem? Is there any solution? or If do I use the TclBlend, can I obtain way to solve this problem? If you have any experience or comment, please let me know. I'm working with: Tcl version is ActiveTcl 8.4. I'm using java sdk 6 And I tried test based on windows and linux both. Thank you. Best regards import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class TclExcuter { public Process oProcess; BufferedReader reader; BufferedWriter writer; public TclExcuter(String[] args) { } public TclExcuter(String args) { } public TclExcuter() { this.runTcl(); } private String runTcl() { String result = ""; String tmp; try { /* over the java version 1.5 */ ProcessBuilder pb =new ProcessBuilder("cmd","/y","/c","tclsh"); pb = pb.directory(new File("C:\\")); pb = pb.redirectErrorStream(true); oProcess = pb.start(); reader = new BufferedReader(new InputStreamReader(oProcess.getInputStream())); writer = new BufferedWriter(new OutputStreamWriter(oProcess.getOutputStream())); } catch (IOException e) { e.printStackTrace(); } return result; } public BufferedReader getReader() { return reader; } public BufferedWriter getWriter() { return writer; } } |
From: Patrick F. <fin...@gm...> - 2008-06-15 14:40:40
|
Have a read of this. Embedding a Tcl Interpreter in Java ==>> http://www.ensta.fr/~diam/tcl/online/Using_Tcl_in_Java-20010106.html 2008/6/14 Kim,Younghun <mys...@ic...>: > Hello dear , > > > > First at all, I'm not sure my question is proper or not to this topic. But, > I'm considering I should use Tcljava. Because I ask to here. > > > > I'm doing a project. In this project I'm making simple java program which > can interact with "tclsh". Java program is designed originally without > tclblend and jacl. In my idea, java can call the "tclsh" by using > 'ProcessBuilder' class. It then gets input/error/ouput-streams of tclsh. If > I handle these three-stream, I may be able to handle tclsh through > java-program.(sample source code is attached below) This is my idea but*, > it doesn't work.* I think I couldn't get these streams. Anyway while > processbuilder are handling tclsh, tclsh process is working on system. > > I guess tclsh, I guess this is a kind of shell, uses own shell, so java > cannot intercept IO streams of it. > > > > How do you think of this problem? > > > > Is there any solution? or > > If do I use the TclBlend, can I obtain way to solve this problem? > > If you have any experience or comment, please let me know. > > > > I'm working with: > > Tcl version is ActiveTcl 8.4. > > I'm using java sdk 6 > > And I tried test based on windows and linux both. > > > > Thank you. > > Best regards > > > > > > import java.io.BufferedReader; > > import java.io.BufferedWriter; > > import java.io.File; > > import java.io.IOException; > > import java.io.InputStreamReader; > > import java.io.OutputStreamWriter; > > > > public class TclExcuter { > > public Process oProcess; > > BufferedReader reader; > > BufferedWriter writer; > > > > public TclExcuter(String[] args) { > > } > > > > public TclExcuter(String args) { > > } > > > > public TclExcuter() { > > this.runTcl(); > > } > > > > private String runTcl() { > > String result = ""; > > String tmp; > > > > try { > > /* over the java version 1.5 */ > > ProcessBuilder pb =new > ProcessBuilder("cmd","/y","/c","tclsh"); > > pb = pb.directory(new > File("C:\\")); > > pb = pb.redirectErrorStream(true); > > oProcess = pb.start(); > > > > reader = new BufferedReader(new > InputStreamReader(oProcess.getInputStream())); > > writer = new BufferedWriter(new > OutputStreamWriter(oProcess.getOutputStream())); > > } catch (IOException e) { > > e.printStackTrace(); > > } > > return result; > > } > > > > public BufferedReader getReader() { > > return reader; > > } > > > > public BufferedWriter getWriter() { > > return writer; > > } > > } > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > tcljava-user mailing list > tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tcljava-user > > |