Python-バックグラウンド運転(nohup、&、2>&1詳細)
1573 ワード
一、スクリプトファイル(test.py)
二、実行スクリプト
三、2>&10はstdin標準入力、ユーザキーボード入力の内容 を表す.1はstdout標準出力を示す、ディスプレイの内容 に出力する.2はstderr標準エラーを表し、エラーメッセージ 2>&1は全体です.>左右にスペースがなく、エラー内容を標準出力にリダイレクトします.
2>&1の&は、ファイル1と1(標準出力)を区別するためであり、2>1であれば、標準出力ではなくファイル1にエラー内容を出力することになる.
四、nohupコマンド
https://blog.csdn.net/suyues/article/details/100046978
https://blog.csdn.net/weixin_42840933/article/details/85780125
# -*- coding: UTF-8 -*-
import time
print("hello"," python")
os.getcwd() #
os.chdir(path) #
while True:
print("start to print %s" % "python")
time.sleep(2)
二、実行スクリプト
[root@localhost ~]# python test.py >my.log
[root@localhost ~]# python test.py >my.log 2>&1
[root@localhost ~]# python test.py 1>my.log # , 1
[root@localhost ~]# python test.py 1>my.log 2>&1 # , 1
[root@localhost ~]# python test.py 1>my.log 2>error.log # , error.log
[root@localhost ~]# python test.py >>my.log
[root@localhost ~]# python test.py >>my.log 2>&1
[root@localhost ~]# python test.py 1>>my.log # , 1
[root@localhost ~]# python test.py 1>>my.log 2>&1 # , 1
[root@localhost ~]# python test.py 1>>my.log 2>>error.log # , error.log
三、2>&1
2>&1の&は、ファイル1と1(標準出力)を区別するためであり、2>1であれば、標準出力ではなくファイル1にエラー内容を出力することになる.
四、nohupコマンド
https://blog.csdn.net/suyues/article/details/100046978
https://blog.csdn.net/weixin_42840933/article/details/85780125