no such file or directory
java远程执行命令报错java.io.IOException: Cannot run program “ifconfig“: error=2, No such file or directory
最新推荐文章于 2024-09-17 19:12:43 发布

shy_snow 于 2020-03-16 10:26:02 发布
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
直接执行ifconfig没问题,但是在java代码里远程执行ifconfig就找不到命令。
session = conn.openSession();
session.execCommand(cmd);
// Cannot run program "ifconfig": error=2, No such file or directory
解决办法:
在 用户的 home 目录下的 文件 .bashrc 加入
export PATH=$PATH:/sbin
然后执行
source .bashrc 就可以执行 ifconfig 命令了
解决办法二:
在用户目录的.bashrc文件里加上 source /etc/profile
原因分析:java远程执行shell应该是非登录shell。非登录shell与登录shell加载的配置文件不同,环境变量不同。
因为非登录shell方式的 .bashrc中的path没有将/sbin目录加入到path中,导致找不到下面的ifconfig命令。只要在用户.bashrc文件中将/sbin目录配置上就行了。
区分方法
如何区分登录 shell 和非登录 shell 呢,可以通过查看 $0 的值,登录 shell 返回 -bash,而非登录 shell 返回的是 bash 。
注意:
执行 exit 命令, 退出的 shell 可以是登录 或者 非登录 shell ;
执行 logout 命令,则只能退出登录 shell,不能退出非登录 shell
附录:登录shell和非登录shell的区别
登录shell配置
用户登陆时,输入用户名和密码后启动的shell通过带--login参数的命令:bash --login而启动的shell加载文件顺序 1. ~/.bash_profile2. ~/.bash_login3. ~/.profile加载 登录即加载主动加载 source.非登陆shell配置
~/.bashrc /etc/bashrc用户登录后,直接运行bash命令启动的shell相关知识
matplotlib字体查找机制探索
【免费】PHP花涧订购系统(源码+数据库)00332资源
onclick触发type=file并上传文件
使input type=“file” 不可编辑
input[type=“file”] change事件第二次不触发
花童的KSHair
No columns to parse from file报错
善绍电子农业百科网
CropNet: Cassava Disease Detection
将字体添加为 XML 资源
原文链接: no such file or directory https://m.huajiangbk.com/newsview792627.html
| 上一篇: 求爱表白送花祝福语精选,5178... | 下一篇: 送花表白情话 给女朋友送花祝福语 |


