Python:File在命令行上工作,但不与crontab一起工作
我有一个文件,看起来是这样的:Python:File在命令行上工作,但不与crontab一起工作,python,crontab,Python,Crontab,我有一个文件,看起来是这样的: #!/usr/bin/python import MySQLdb import subprocess from subprocess import call import re conx = MySQLdb.connect (user = 'root', passwd = '******', db = 'vaxijen_antigens') cursor = conx.cursor() cursor.execute('select * from sequence
#!/usr/bin/python
import MySQLdb
import subprocess
from subprocess import call
import re
conx = MySQLdb.connect (user = 'root', passwd = '******', db = 'vaxijen_antigens')
cursor = conx.cursor()
cursor.execute('select * from sequence')
row = cursor.fetchall()
f = open('/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta', 'w')
for i in row:
f.write('>'+i[0].strip()+'\n')
s = re.sub(r'[^\w]','',str(i[1]))
s = ''.join(s)
for k in range(0, len(s), 60):
f.write('%s\n' % (s[k:k+60]))
f.write('\n')
f.close()
subprocess.call(['formatdb', '-p', 'T', '-i', r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])
从命令行运行该文件没有问题,但当我尝试使用crontab运行该文件时,会出现以下错误:
File "/home/rv/ncbi-blast-2.2.23+/db/formatdb.py", line 29, in <module>
subprocess.call(['formatdb', '-p', 'T', '-i',
r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])
OSError: [Errno 2] No such file or directory
文件“/home/rv/ncbi-blast-2.2.23+/db/formatdb.py”,第29行,在
子进程调用(['formatdb','-p',T','-i',,
r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])
OSError:[Errno 2]没有这样的文件或目录
我不明白,这个文件存在于那个目录中,我已经仔细检查过了。我尝试将文件路径转换为原始字符串,因此在路径之前使用小写字母“r”,但也没有这样做。cron守护进程通常只提供非常有限的路径。要么在crontab中放一个更完整的路径,要么在Python代码中使用完整的路径名。我怀疑它在抱怨子流程调用中指向“formatdb”的路径。尝试将其更改为完整路径:
subprocess.call(['/home/path/formatdb', ...])
我已经在crontab文件中输入了路径,我将尝试在python文件中输入完整路径