zoukankan      html  css  js  c++  java
  • DATAX 实现java调用cmd 系统控制台,实现在开发工具中内嵌datax

    二话不说直接给代码

     1 package UTIL;
     2 import java.io.BufferedReader;
     3 import java.io.BufferedWriter;
     4 import java.io.IOException;
     5 import java.io.InputStreamReader;
     6 import java.io.OutputStream;
     7 import java.io.OutputStreamWriter;
     8 
     9 public class CMD {
    10     Process process;
    11     public void CmdTest(String json) throws IOException {
    12         process=Runtime.getRuntime().exec("cmd");
    13         new Thread(){
    14             public void run() {
    15                 try {
    16                     BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
    17                     bw.write("CHCP 65001");
    18                     bw.newLine();
    19 
    20                     bw.write("e:");
    21                     bw.newLine();
    22 
    23                     bw.write("cd E:\DATAX\datax\bin");
    24                     bw.newLine();//因为读取时是一行行读取的,不加newline无法继续往下读
    25 
    26                     bw.write("python datax.py "+json);
    27                     bw.newLine();
    28 
    29 
    30                     bw.flush();
    31                 } catch (IOException e) {
    32                     // TODO Auto-generated catch block
    33                     e.printStackTrace();
    34                 }
    35             }
    36         }.start();;
    37         new Thread() {
    38             public void run() {
    39                 try {
    40                     BufferedReader br=new BufferedReader(new InputStreamReader(process.getInputStream()));
    41                     String cmdout="";
    42                     while ((cmdout=br.readLine())!=null) {
    43                         System.out.println(cmdout);
    44                     }
    45                 } catch (IOException e) {
    46                     // TODO Auto-generated catch block
    47                     e.printStackTrace();
    48                 }
    49             }
    50         }.start();
    51 
    52     }
    53 
    54     public static void main(String[] args) throws IOException {
    55         CMD cmd=new CMD();
    56         String json="E:\DATAX\Workplace\TEXT\csv2csv.json";
    57         cmd.CmdTest(json);
    58 
    59     }
    60 }
  • 相关阅读:
    盘的转——使用缓动函数完成动画
    espnet环境配置(window)
    2021.9.8 Hadoop集群
    2021.9.7 开学第一课
    RS-422与RS-485
    70 进程创建的优化设计 下
    RGB液晶接口
    matlab2018a安装激活教程
    sed初级教程
    centos无法添加默认网关
  • 原文地址:https://www.cnblogs.com/smartisn/p/12390964.html
Copyright © 2011-2022 走看看