LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron/writing files (https://www.linuxquestions.org/questions/linux-newbie-8/cron-writing-files-897513/)

leavage 08-15-2011 08:43 PM

Cron/writing files
 
I have a python script that writes a file when ran. This program works fine when I run it from command line. So I tried to get it to run as a cron job. But I get an error 'Runtime error: Cannot open Display'.
What my program does is it opens a new file(creates the file), and writes a line of data to this file. Ive checked the permissions and it really seems that I have the correct permissions to do this.
I don't really see why it is failing under cron. Any ideas?

jlinkels 08-15-2011 09:05 PM

apparently you are accessing X, is it a GUI program?

Use absolute paths everywhere. Don't assume anything.

Can you post the offending line from your cron file?

Can you post your code?

jlinkels

leavage 08-17-2011 12:34 AM

I have figured out that the problem is in the X server and the lines of code

import pylab
from pylab import *

Why does python require the X server?
I need pylab because it has the sys.argv commmand.

jlinkels 08-17-2011 02:16 PM

pylab is a plotting library, so it is logical it requires X in one or another way.

However, the sys.argv command is not contained in pylab but in sys.

So you would use:
Code:

import sys
sys.argv

You don't need to call from sys import * as long as you use the module name in front of argv, so sys.argv

jlinkels


All times are GMT -5. The time now is 09:16 AM.