从crontab运行时,os.system返回值256

时间:2017-12-15 12:12:38

标签: python python-3.x cron os.system

当我通过命令行运行代码时,我的代码运行完美,但是当系统尝试使用cron运行代码时,它不会执行另一个文件。 os.system(file)返回值256,我无法理解原因。

from datetime import datetime, timedelta
import requests
import os
print(1)

#Login API to get the token
reqLogin = requests.post('http://139.162.29.201:3001/auth/sign_in', json = {'email': 'aa', 'password': 'aa'})
reqLogin = reqLogin.json()
print(2)
#Get all the clients
reqClient = requests.request('GET', 'http://139.162.29.201:3001/clients', headers = {'Authorization': 'JWT '+ reqLogin['token']})
reqClient = reqClient.json()
print(3)
#Initialize time
#time = (datetime.now() + timedelta(hours = 5, minutes = 30)).strftime('%H:%M:%S')
time = "05:59:50"
timeInSecondsList = time.split(":")
time = timedelta(hours = int(timeInSecondsList[0]), minutes = int(timeInSecondsList[1]))
print(4)
#Initialize date
dateTime = (datetime.now() + timedelta(hours = 5, minutes = 30)).strftime('%Y-%m-%d')
dateTimeYesterday = (datetime.now() + timedelta(days = -1, hours = 5, minutes = 30)).strftime('%Y-%m-%d')
print(5)
for eachClient in reqClient:
    #Get the shift timing against the client
    reqShiftTiming = requests.post('http://139.162.29.201:3001/getShiftTiming', headers = {'Authorization': 'JWT '+reqLogin['token']}, json = {'clientId': eachClient['clientId']})
    reqShiftTiming = reqShiftTiming.json() 
    print(6)
    shiftAList = reqShiftTiming[0]['shiftA'].split(":")
    shiftBList = reqShiftTiming[0]['shiftB'].split(":")
    shiftCList = reqShiftTiming[0]['shiftC'].split(":")
    print(7)
    if time == timedelta(hours = int(shiftBList[0]), minutes = int(shiftBList[1]) - 1):
        print(8)
        file = 'python /quad/finalMachineEfficiency.py '+ eachClient['clientId'] + ' ' + timeInSecondsList[0] + ':' + timeInSecondsList[1] + ' ' + dateTime
        os.system(file)
        print(os.system(file))
    if time == timedelta(hours = int(shiftCList[0]), minutes = int(shiftCList[1]) - 1):
        print(9)
        file = 'python /quad/finalMachineEfficiency.py '+ eachClient['clientId'] + ' ' + timeInSecondsList[0] + ':' + timeInSecondsList[1] + ' ' + dateTime
        os.system(file)
        print(os.system(file))
    if time == timedelta(hours = int(shiftAList[0]), minutes = int(shiftAList[1]) - 1):
        print(10)
        file = 'python /quad/finalMachineEfficiency.py '+ eachClient['clientId'] + ' ' + timeInSecondsList[0] + ':' + timeInSecondsList[1] + ' ' + dateTimeYesterday
        os.system(file)
        file2 = 'python /quad/finalOee.py ' + eachClient['clientId'] + ' ' + timeInSecondsList[0] + ':' + timeInSecondsList[1] + ' ' + dateTimeYesterday
        os.system(file2)
        print(os.system(file), os.system(file2))
print("callefficiency.py ended", dateTime)

按命令行输出

callefficiency.py started
1
2
3
4
5
6
7
10
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
0 0
6
7
10
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
0 0
6
7
10
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
0 0
6
7
10
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
finalMachineEfficiency.py started 2017-12-14
finalMachineEfficiency.py ended 2017-12-14
finaloee.py started 2017-12-14
finaloee.py ended 2017-12-14
0 0
callefficiency.py ended 2017-12-15

cron输出

callefficiency.py started
1
2
3
4
5
6
7
10
256 256
6
7
10
256 256
6
7
10
256 256
6
7
10
256 256
callefficiency.py ended 2017-12-15

我想知道可能的原因是什么,以及如何解决此错误。

0 个答案:

没有答案