1

I'm trying to write a program that can convert a bunch of .doc files to .txt in Python. It should be able to run on multiple platforms and able to be totally self-contained.

To achieve this, I am trying to run the Antiword binary from within my working directory. Both the directory !Antiword (which contains the binary, also called "!Antiword") as well as the file calling executable (phil.py) are within the same directory. I am trying to run the same command that works in the command line of Mac OSX, antiword example.doc > example.txt.

To run this binary when it is stored inside the current working directory, I would like to run something like this via subprocess.Popen(): /Users/hudsonnash/Dropbox/Mac/Desktop/philippines_download/control/!Antiword/!Antiword example.doc > example.txt.

The problem is that I keep getting a Permission Denied error. When I use sudo /Users/hudsonnash/Dropbox/Mac/Desktop/philippines_download/control/!Antiword/!Antiword example.doc > example.txt, I get a cannot execute binary file error.

To fix this error, I have tried changing the permissions of the binary file from within my Python script. I attempted to turn on permissions for the user to execute the file via os.chmod(antiword,S_IWUSR|S_IREAD|S_IXUSR).

This is the problematic code block:

def convert_file_type(di,pswrd):
    antiword = '/Users/hudsonnash/Dropbox/Mac/Desktop/philippines_download/control/!Antiword/!Antiword'
    os.chmod(antiword, S_IWUSR|S_IREAD|S_IXUSR)
    uz_list = [os.path.join(di,f) for f in os.listdir(di)]
    for f in uz_list:
        base,ext=os.path.splitext(f)
        if ext != 'txt':
            p = subprocess.Popen(antiword+' '+f+' > '+base+'.txt',shell=True,stdout=subprocess.PIPE)

This is the output to the console:

/bin/sh: /Users/hudsonnash/Dropbox/Mac/Desktop/philippines_download/control/!Antiword/!Antiword: cannot execute binary file
b''
b''
/bin/sh: /Users/hudsonnash/Dropbox/Mac/Desktop/philippines_download/control/!Antiword/!Antiword: cannot execute binary file
hn6
  • 11
  • 2
  • Welcome to the forum, Hudson! I will be interested to see the answer, particularly because [another post](https://stackoverflow.com/questions/60656761/antiword-converts-doc-into-an-empy-txt-file) seems to have a similar problem as you. – Mike Jun 16 '22 at 20:45

0 Answers0