操作系统从crontab运行时返回值256

2024-04-24 18:32:17 发布

您现在位置:Python中文网/ 问答频道 /正文

当我通过命令行运行代码时,我的代码运行得很好,但是当系统尝试使用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)

通过命令行输出

^{pr2}$

由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

我想知道可能的原因是什么,我能做些什么来解决这个错误。在


Tags: pydatetimetimeossystemfiletimedeltaint