的Linux输出重定向守护进程不工作

问题描述:

我有一个python脚本是这样的:的Linux输出重定向守护进程不工作

while True: 
    print("ok") 

我创建了一个守护进程test.service:

[Unit] 
Description=Un service de test. 

[Service] 
Type=idle 
ExecStart=/usr/bin/python3 /home/andy/Desktop/test.py > /home/andy/Desktop/test.log 2>&1 

[Install] 
WantedBy=multi-user.target 

我主动将其与须藤systemctl开始测试。服务。 未创建日志文件:输出重定向不起作用。

当我写systemctl状态test.service,我有:

● test.service - Un service de test. 
    Loaded: loaded (/etc/systemd/system/test.service; disabled; vendor preset: enabled) 
    Active: active (running) since Wed 2017-10-18 00:50:29 CEST; 20s ago 
Main PID: 3651 (python3) 
    Tasks: 1 (limit: 4915) 
    CGroup: /system.slice/test.service 
      └─3651 /usr/bin/python3 /home/andy/Desktop/test.py > /home/andy/Desktop/test.log 2>&1 

oct. 18 00:50:29 andy-G551JW systemd[1]: Started Un service de test.. 
oct. 18 00:50:29 andy-G551JW python3[3651]: ok 
oct. 18 00:50:29 andy-G551JW python3[3651]: ok 

我如何可以重定向在后台脚本的输出?

+0

可能重复[python-daemon和stdout](https://*.com/questions/11146128/python-daemon-and-stdout) – jww

请勿重定向其输出。让脚本打印到标准输出。 Systemd将其输出存储在systemd日志中,您可以使用journalctl -u testsystemctl status test查看它。

+0

我刚刚2“ok”一段时间True:print(“好”)。这是正常的吗? – Andy