package test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ResourceBundle;
public class Command {
public static void main(String[] args) throws Exception {
ResourceBundle resource = ResourceBundle.getBundle("config");
Thread gitThread = new gitStartThread(resource);
gitThread.start();
gitThread.join();
System.out.println("haha");
}
static class gitStartThread extends Thread {
ResourceBundle resource;
public gitStartThread(ResourceBundle resource) {
this.resource = resource;
this.setDaemon(true);
}
@Override
public void run() {
Process process;
try {
process = Runtime.getRuntime().exec(resource.getString("cmd"));
System.out.println("写入cmd成功");
PrintWriter writer = new PrintWriter(process.getOutputStream());
writer.println(resource.getString("GITCMD"));
writer.flush();
System.out.println("写入GIT成功,开始拉取...");
writer.close();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("gitstart运行异常");
e.printStackTrace();
} finally {
}
}
}
}
如上这里线程并不会被运行,而是主线程一下子运行完了,子线程没被执行
注:
resource.getString("cmd")拿到的字符是cmd
resource.getString("GITCMD")拿到的字符是git clone -b wlnsss_dev https://gitee.com/Wx
上面拉取git的字符乱写的,反正程序的最终作用就是
这是一个通过Java调用cmd拉取git到本地的程序,如果在join方法前加入线程睡眠似乎会正常执行,请各位大佬讲解下这是为什么,谢谢啦