51Testing软件测试论坛

标题: 请问谁在java程序中调用过tcl脚本,并获取返回值? [打印本页]

作者: allenzhao28    时间: 2011-5-9 12:07
标题: 请问谁在java程序中调用过tcl脚本,并获取返回值?
我现在使用runtime.exec打开tcl后,进程一直没返回。

我的tcl脚本为test.tcl。我想在java程序中运行这个脚本,并且获取此脚本的输出。

求达人帮忙看一下啊
作者: TIB    时间: 2011-5-9 15:35
可考虑将TCL的脚本用FreeWrap转换成exe文件,再用java来调用
作者: smile665    时间: 2011-5-9 21:02
可以在Java获取脚本的输出的  我写过例子,是调用shell的 调用TCL都是一样的吧
见:http://www.51testing.com/index.p ... space-itemid-224274

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class CallShell {
    public static void main(String[] args) {
        try {
            // 被注释掉的这个仅仅是执行了test.sh脚本,但没有获取它的输出
            // Runtime.getRuntime().exec("/home/master/workspace/shell/test.sh");
            Process process = Runtime.getRuntime().exec(
                    "/home/master/workspace/shell/test.sh");
            InputStreamReader ir = new InputStreamReader(process
                    .getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line;
            while ((line = input.readLine()) != null)
                System.out.println(line);
            input.close();
            ir.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2