【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'")
相关推荐
林开落L27 分钟前
库的制作与原理
linux·开发语言·动静态库·库的制作
2401_888423091 小时前
Linux软件编程-线程(2)
linux
共享家95272 小时前
linux-数据链路层
linux·网络·macos
Demisse2 小时前
[Linux] Linux文件系统基本管理
linux·运维·服务器
小米里的大麦3 小时前
025 理解文件系统
linux
打不了嗝 ᥬ᭄4 小时前
Linux 信号
linux·开发语言·c++·算法
禁默4 小时前
进程替换:从 “改头换面” 到程序加载的底层逻辑
linux·运维·服务器
gameatp5 小时前
从 Windows 到 Linux 服务器的全自动部署教程(免密登录 + 压缩 + 上传 + 启动)
linux·服务器·windows
穷人小水滴5 小时前
在 windows 运行 flatpak 应用 (WSL)
linux·windows·ubuntu
一只拉古5 小时前
DevOps 的 Linux 基础(第一部分)
linux·自动化运维·devops