免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4075 | 回复: 10
打印 上一主题 下一主题

Runtime.getRuntime().exec问题!急急 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-22 12:02 |只看该作者 |倒序浏览
我在甲类有二个按钮A和B

A作用:Runtime.getRuntime().exec启动另外一个乙类;
B作用:关闭A所打开的乙类;

A我已经实现了,
我想知道B怎么实现?
急急!!!
谢谢!!!

论坛徽章:
0
2 [报告]
发表于 2005-11-22 12:07 |只看该作者
关闭乙类?

乙类是指?

论坛徽章:
0
3 [报告]
发表于 2005-11-22 12:14 |只看该作者
乙类就是一个新打开的一个窗口,
两个类都是无限循环的
所以要新开窗口

论坛徽章:
0
4 [报告]
发表于 2005-11-22 12:29 |只看该作者
乙类是一个java类么?那不应该用RUntime.exec

论坛徽章:
0
5 [报告]
发表于 2005-11-22 12:50 |只看该作者
是的,说白了就是:这两个类是独立的,现在要用甲类来控制乙类的运行各停止.

论坛徽章:
0
6 [报告]
发表于 2005-11-22 13:15 |只看该作者
而且两个类都无际循环的

论坛徽章:
0
7 [报告]
发表于 2005-11-22 13:16 |只看该作者
没办法了,还是重写吧

论坛徽章:
0
8 [报告]
发表于 2005-11-22 13:19 |只看该作者
把A、B类的关键部分代码给出来或许会知道怎么解决

论坛徽章:
0
9 [报告]
发表于 2005-11-22 13:54 |只看该作者
简化后大概如下:
甲类:
                if(e.getSource() == startJB)        //        start the service of this server. there is no real function now;
                {
                        /*
                        try{
                                et = new ExamThread();
                        }catch(Exception eee){
                                nullError("测试系统启动失败!","系统");
                        }
        */       
                try        {        //        try to start the service of exam online
                        setLog("启动在线测试服务器...");
                        Runtime testR = Runtime.getRuntime();
                        testR.exec("java ExamServer start");
                        nullError("已启动在线测试服务器!","系统");
                        startJB.setEnabled(false);
                        stopJB.setEnabled(true);
                        setLog("启动在线测试服务器成功!");
                }catch(Exception exxx){
                                System.err.println("Runtime %Wrong:"+exxx.toString());
                        }                       
                        //this.chatStart();       
                }
                if(e.getSource() == stopJB)                //         stop the service of this server. there is no real function now;
                {
                try        {        //        try to start the service of exam online
                        setLog("关闭在线测试服务器...");
                        Runtime testR = Runtime.getRuntime();
                        testR.exec("java ExamServer stop");
                        nullError("已关闭在线测试服务器!","系统");
                        startJB.setEnabled(false);
                        stopJB.setEnabled(true);
                        setLog("关闭在线测试服务器成功!");
                        startJB.setEnabled(true);
                        stopJB.setEnabled(false);
                }catch(Exception exxx){
                                System.err.println("Runtime %Wrong:"+exxx.toString());
                        }
乙类:
public static void main (String args[])
{
        if(args[0].toString().equals("start"))
        {
                ...运行的主程序
                System.out.println("starting ...*"+args[0]);       
        }
        else if(args[0].toString().equals("stop"))
        {
                ...要求关闭主程序
                System.out.println("stoped!*"+args[0]);
        }else
        {
                System.out.println("请使用java ExamServer start|stop!");
        }       
}

ps:现在主要是再次调用java ExamServer stop 时不能关闭之前运行的ExamServer

论坛徽章:
0
10 [报告]
发表于 2005-11-22 14:11 |只看该作者
ExamServer这个类不能增加两个方法,一个start(),一个stop()么?

然后你实例化一个ExamServer,可以调用这两个方法即可
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP