OS: ubuntu 20.0 I write a simple python with print
import time
a = 0
while 1:
a +=1
print(a)
time.sleep(1)
and I run command
nohup python3 test2.py > 3.log 2>&1 &
then next
cat 3.log
only got
nohup: ignoring input
if I remove last & run
nohup python3 test2.py > 3.log 2>&1
get 3.log output
1
2
3
4
but nohup will be kill after terminor close .how can I get output with &
django@django-s-1vcpu-1gb-sgp1-01:~/swap_hb$ nohup python3 test2.py > 3.log 2>&1
^C
django@django-s-1vcpu-1gb-sgp1-01:~/swap_hb$ cat 3.log
nohup: ignoring input
1
2
3
4
5
6
7
8
Traceback (most recent call last):
File "test2.py", line 6, in <module>
time.sleep(1)
KeyboardInterrupt
django@django-s-1vcpu-1gb-sgp1-01:~/swap_hb$ ^C
django@django-s-1vcpu-1gb-sgp1-01:~/swap_hb$ nohup python3 test2.py > 3.log 2>&1 &
[3] 83030
django@django-s-1vcpu-1gb-sgp1-01:~/swap_hb$ cat 3.log
nohup: ignoring input
django@django-s-1vcpu-1gb-sgp1-01:~/swap_hb$