java控制远程linux命令写入文件时的问题

java控制远程linux命令写入文件时的问题,第1张

这个session好像是一个ssh的开源库,没有用过,感觉实现其实差不多,就是第一个进程执行完了,再执行下一个,如果该开源库控制或者不知道结束状态(一般不会),可以用sleep看看能不能让四个进程串行执行完毕

Session sess = conn.openSession()

sess.execCommand(..)

Thread.currentThread().sleep(5000)

再执行下一个命令

______________________________________________________

楼主是用Runtime实现调用远程命令吗,

试试看用process的waitfor()方法,等待上一个进程执行完了再执行下一个

Process child1 = Runtime.getRuntime().exec(命令1);

child1.waitFor()

.....

....

Process child4 = Runtime.getRuntime().exec(命令4);

child1.waitFor()

public static void main(String[] args){

try {

File file = new File("test/pp/tt/asd.txt")

File parent = file.getParentFile()

if(parent!=null&&!parent.exists()){

parent.mkdirs()

}

file.createNewFile()

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8487070.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存