【linux】ls: write error: No such file or directory--2>/dev/null解决

问题:

执行adb指令

复制代码
latest_file = run_command(
        f"adb -s {TBOX_DEVICE_NAME} shell 'cd /mnt/sdcard/dlt && ls -t dlt_4g*.dlt.gz 2>/dev/null | head -1'").strip()
key_log = run_command(
        f"adb -s {TBOX_DEVICE_NAME} shell 'cd /mnt/sdcard/dlt && gunzip -c \"{latest_file}\" | grep -a \"waitForHeartBeatAck succ\" | tail -n 10'")

偶发报错:

ls: write error: No such file or directory

这个错误表明在查找最新的DLT文件时,ls命令可能遇到了问题。以下是完整的解决方案,包含错误处理和稳定性改进:

解决方法:

添加 2>/dev/null 重定向错误输出

复制代码
latest_file = run_command(
        f"adb -s {TBOX_DEVICE_NAME} shell 'cd /mnt/sdcard/dlt && ls -t dlt_4g*.dlt.gz 2>/dev/null | head -1'").strip()
key_log = run_command(
        f"adb -s {TBOX_DEVICE_NAME} shell 'cd /mnt/sdcard/dlt && gunzip -c \"{latest_file}\" | grep -a \"waitForHeartBeatAck succ\" | tail -n 10'")
相关推荐
一位摩羯座DBA35 分钟前
Redhat&Centos挂载镜像
linux·运维·centos
学习3人组36 分钟前
CentOS配置网络
linux·网络·centos
weixin_307779131 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
漫步企鹅2 小时前
【蓝牙】Linux Qt4查看已经配对的蓝牙信息
linux·qt·蓝牙·配对
cui_win2 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
梦在深巷、2 小时前
MySQL/MariaDB数据库主从复制之基于二进制日志的方式
linux·数据库·mysql·mariadb
冰橙子id2 小时前
linux系统安全
linux·安全·系统安全
stark张宇3 小时前
VMware 虚拟机装 Linux Centos 7.9 保姆级教程(附资源包)
linux·后端
Johny_Zhao3 小时前
Ubuntu系统安装部署Pandawiki智能知识库
linux·mysql·网络安全·信息安全·云计算·shell·yum源·系统运维·itsm·pandawiki
悲伤小伞3 小时前
linux_git的使用
linux·c语言·c++·git