Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell standrad错误时停止系统错误_Shell_Unix_Awk - Fatal编程技术网

Shell standrad错误时停止系统错误

Shell standrad错误时停止系统错误,shell,unix,awk,Shell,Unix,Awk,我正在编写一个启动无限循环的AWK脚本-因此在该脚本中,我验证指定路径中是否存在文件,如果是这样,我将退出无限循环: while ( ("ls -l /tmp/STOP" |& getline var4) > 0) { exit 0 } close("ls -l /tmp/STOP") 问题是,当文件不存在时,我在运行时遇到标准错误: ls:/tmp/STOP:没有这样的文件或目录 如何避免控制台上出现此标准错误消息?如果您不特别想要目录列表,请不要使用ls。类似

我正在编写一个启动无限循环的AWK脚本-因此在该脚本中,我验证指定路径中是否存在文件,如果是这样,我将退出无限循环:

while ( ("ls -l /tmp/STOP" |& getline var4) > 0) {
        exit 0
}
close("ls -l /tmp/STOP")
问题是,当文件不存在时,我在运行时遇到标准错误:

ls:/tmp/STOP:没有这样的文件或目录


如何避免控制台上出现此标准错误消息?

如果您不特别想要目录列表,请不要使用
ls
。类似于test-e/tmp/STOP的退出代码会更好

 if (! system ("test -e /tmp/STOP")) exit 0

尝试将错误流重定向到
/dev/null

while ( ("ls -l /tmp/STOP 2>/dev/null" |& getline var4) > 0) {
    exit 0
}
close("ls -l /tmp/STOP")

sleep命令之所以存在,是因为您不想疯狂地生成进程。

感谢您的提示,我尝试了“ls-l/tmp | grep STOP”命令,它工作得非常好,在文件不正常的情况下没有报告错误
BEGIN {
  while ( system("sleep 1; test -f /tmp/STOP") ) print "The file is not there..."
  exit
}