最近使用jsch连接linux执行adb命令但是发现返回的信息是:
bash: adb: command not found
也就是它没有找到我的adb命令,然后直接$PATH返回的环境变量也并不是我系统所配置的,
证明此种方式没有记载我的环境变量.
解决方法1:
在你执行的命令前加入source /etc/profile && source ~/.bash_profile && source ~/.bashrc,手动记载环境变量.
channelExec.setCommand( "source /etc/profile && source ~/.bash_profile && source ~/.bashrc && adb devices" );
解决方法2:
我们改用shell方式发送命令,shell方式是可以自动加载系统的环境变量的.
shell方式会导致断开连接脚本也就停止了,所以如果需要在断开连接脚本继续运行,那么需要添加nohup命令
发表评论