【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'")
相关推荐
zzzzzz31019 小时前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode19 小时前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
A小辣椒3 天前
TShark:Wireshark CLI 功能
linux
A小辣椒3 天前
TShark:基础知识
linux
AlfredZhao3 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao3 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334664 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪4 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠4 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush44 天前
嵌入式linux学习记录十四、术语
linux·嵌入式