java代码连接linux后,执行linux命令
我需要执行的linux命令是:
hdfs dfs -put [本地目录] [hadoop目录]
把jar包复制到hdfs某个文件夹下,
导入的jar包,
import com.jcraft.jsch.ChannelExec;
新建空对象:
ChannelExec openChannel =null;
在连接关闭前:
//把jar包放到hdfs目录
openChannel = (ChannelExec) session.openChannel("exec");
openChannel.setCommand("hdfs dfs -put "+remotePath+localFile+" .hiveJars");//括号内放的是linux命令
int exitStatus = openChannel.getExitStatus();
openChannel.connect();
openChannel.setCommand("需要执行的linux命令");
------------------------------------------------------------------------------------------------------------------------------------
下面是在网上找到的别的方法 :(针对于我的需求失败)
Runtime.getRuntime().exec("sh generator.sh").waitFor();
一直报找不到指定文件,网上找了很多方法也不行,这是在网上找的解决方案(没能解决我的问题)附链接:https://www.cnblogs.com/zhanzhuang/p/9304502.html。

浙公网安备 33010602011771号