I try to use Python envoy for better access to Shell programs. But i have a problem that i want to delete all items of a folder, but envoy can’t handle my varaible:
import envoy
import os
# Check for a empty folder.
if len(os.listdir(csv_save_path)) != 0:
for item in os.listdir(csv_save_path):
result = envoy.run('rm -v',item)
print result.std_out
print result.std_err
Output:
"rm: missing operand\nTry `rm --help' for more information.\n"
I don’t want use subprocces. Anyone a idea what is wrong?
Edit:
Thank for your quick response. Now i get this error message:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib64/python2.7/site-packages/envoy/core.py", line 40, in target
bufsize=0,
File "/usr/lib64/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
*** AttributeError: 'NoneType' object has no attribute 'returncode'
But i check on the path of the file, with and without path, it’s failing.
Edit: The Solution is to use %s to get the item to the right place.
import envoy
import os
# Check for a empty folder.
if len(os.listdir(csv_save_path)) != 0:
for item in os.listdir(csv_save_path):
result = envoy.run('rm -v %s' % item)
print result.std_out
print result.std_err
so far
Try this