【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'")
相关推荐
cqsztech3 小时前
oracle linux 10 +pg18 源码安装要点
linux·数据库·oracle
奥尔特星云大使3 小时前
ALTER 与 UPDATE、DROP 与 DELETE区别
linux·运维·数据库·mysql
duangww4 小时前
部署sapui5应用到linux
linux·sap fiori
siriuuus4 小时前
Linux ssh/scp/sftp命令使用及免密登录配置
linux·ssh·sftp·scp
teacher伟大光荣且正确6 小时前
Linux 下编译openssl
linux·运维·服务器
dlz08366 小时前
--group-start/--group-end 能不能解决 OpenSSL 1.0 vs 1.1 的优先级问题?
linux·运维·服务器·软件需求
小池先生7 小时前
activemq延迟消息变成实时收到了?
linux·数据库·activemq
tryCbest8 小时前
Linux系统下安装使用Redis
linux·运维·redis
AuroBreeze9 小时前
xv6-2023 - primes Lab
linux·运维·服务器