• JSON 级 Process


     1     @Override
     2     public void run() {
     3         StatusPanel.isRunning = true;
     4         this.setName("ExecuteThread");
     5 
     6         String exe = "python";
     7         String command = "C:\Users\Administrator\Desktop\nfv.py";
     8         String num1 = StatusPanel.targetTextField.getText();
     9         String[] cmdArr = new String[] {exe,command,num1};
    10         logger.info(exe+" "+command+" "+num1);
    11         JProgressBar progressBar = StatusPanel.progressTotal;
    12         Process process = null;
    13         InputStream in=null;
    14         try {
    15             int rs = 0;
    16             progressBar.setValue(0);
    17             ProgressThread progressThread = new ProgressThread();
    18             progressThread.start();
    19             ProcessBuilder builder = new ProcessBuilder("python","C:\Users\Administrator\Desktop\nfv.py");
    20             builder.redirectErrorStream(true);
    21             process = builder.start();
    22             in = process.getInputStream();
    23             BufferedReader br = new BufferedReader(new InputStreamReader(in));
    24             String output = null;
    25 
    26             while (null != (output = br.readLine()))
    27             {
    28                logger.info(output);
    29             }
    30             rs = process.waitFor();
    31            logger.info(String.valueOf(rs));
    32 
    33 
    34             progressBar.setValue(100);
    35             JOptionPane.showMessageDialog(null,"转换完成","信息",JOptionPane.INFORMATION_MESSAGE);
    36         } catch (Exception e) {
    37             progressBar.setValue(0);
    38             JOptionPane.showMessageDialog(null,"转换失败","信息",JOptionPane.ERROR_MESSAGE);
    39             logger.error(Utils.getStackMsg(e));
    40         }finally {
    41             StatusPanel.buttonStartNow.setEnabled(true);
    42             StatusPanel.isRunning = false;
    43             try {
    44                 in.close();
    45             } catch (IOException e) {
    46                 e.printStackTrace();
    47             }
    48         }
    49     }
     1     @Override
     2     public void run(){
     3         this.setName("ProgressThread");
     4         JProgressBar progressBar = StatusPanel.progressTotal;
     5         while (progressBar.getValue() != 100) {
     6             try {
     7                 JSONObject jsonTask =new JSONObject(Utils.readFile("C:\Users\Administrator\Desktop\task.json"));
     8                 JSONObject task = jsonTask.getJSONObject("default");
     9                 int progress = task.getInt("progress");
    10                 if (progress> progressBar.getValue()){
    11                     progressBar.setValue(progress);
    12                 }
    13                 Thread.sleep(1000);
    14             } catch (Exception e) {
    15 //               logger.error(Utils.getStackMsg(e));
    16                 e.printStackTrace();
    17             }
    18 
    19         }
    20     }
  • 相关阅读:
    Windows编程系列:Windows中的消息
    python 日志 logging模块
    wx-xcx
    大坑:perspectiveTransform
    在移动硬盘上装系统
    Django
    双边滤波(Bilateral filter)
    Mesh Deformation with Laplacian Coordinates
    C++五十一篇 -- VS2017开发人员新闻无法联网
    idea 修改Git密码和账号后,Git提交账号的没有改变
  • 原文地址:https://www.cnblogs.com/aloneblog/p/9440545.html
Copyright © 2020-2023  润新知