linux 输出重定向到文件,文件在程序运行中被删除,程序会怎样

linux 输出重定向到文件,文件在程序运行中被删除,程序会怎样:
实测:程序继续运行,只是不输出到文件了。

另外两种重定向,真实输出文本的时间不一致:
1.程序结束后,写入到out.txt历史打印(打开文件没有内容);
cd /home
python3 lll.py > out.txt 2>&1

lll.py

import requests, time, datetime

for i in range(1000):
    res = requests.get('http://*:8000/get_asso_id/?tablename=dddddd')
    print(datetime.datetime.now(), '-' * 20, res.text + '\n')
    time.sleep(1)

2.程序运行中,实时写入到out.txt(打开文件内容在增加)
cd /home
./test.sh > outsh.txt 2>&1

test.sh

#!/bin/bash

for((i=1; i< 301111; i++));
  do
      echo "Hello World !"
      sleep 1;
  done

最后为执行结果输出地址,一般配置“ >/dev/null 2>&1 & ”表示不打印在任
何地方,相当于个黑洞。
注意必须是/dev/下

你可能感兴趣的:(linux 输出重定向到文件,文件在程序运行中被删除,程序会怎样)