I am trying to insert csv file to mysql table using sub process.call from other script but receiving this error.I don't know where am i going wrong I checked my file and everything looks fine.
def ringoCallback3(filename):
#Run the RINGO insert script
tmp = filename.split('/')
just_filename = tmp[-1]
new_filename = "/home/toor/doneringofiles/%s" % just_filename
retval = subprocess.call(["/usr/local/bin/ringo.py",filename])
os.rename(filename, new_filename)
return retval
dirlist = [ ['/home/toor/ringolist',ringoCallback3]]
while (True):
# Go through each of the directories
for mylist in dirlist:
check_dir = mylist[0]
callback = mylist[1]
# get the list of files in the directory
filelist = os.listdir(check_dir)
for this_file in filelist:
if ((this_file == ".") or (this_file == "..") or (this_file == "doneringofiles")):
print "Skipping self and parent"
continue
full_filename = "%s/%s" % (check_dir, this_file)
# Get the modification time of the file
first_stat = os.stat(full_filename)[8]
# Sleep for 1 second
time.sleep(1)
# Get the modification time again
second_stat = os.stat(full_filename)[8]
# If the modication time has not changed, then the file is stable
# and can be sent to the callback
if (first_stat == second_stat):
callback(full_filename)
# Now sleep for 30 seconds before doing the whole lot again
time.sleep(30)
When I run this code : I get this error:
Traceback (most recent call last):
File "./dirmon.py", line 80, in <module>
callback(full_filename)
File "./dirmon.py", line 44, in ringoCallback3
retval = subprocess.call(["/usr/local/bin/ringo.py",filename])
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
This caused because /usr/local/bin/ringo.py
is not executable by the user that your script is running as.
You can check this, by trying to run the script from a shell (as the same user that your script runs as):
$ /usr/local/bin/ringo.py
You either need to make it executable with the chmod
command, or call the subprocess like this:
subprocess.call(["python", "/usr/local/bin/ringo.py",filename])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.