0

I am trying to convert multiple .doc files to .docx format using antiword. How to write a command like this:

for file in os.listdir(directory):
    subprocess.run("antiword file > file+'.docx'")

it shows this error:

[Errno 2] No such file or directory: "antiword file > file+'.docx'": "antiword file > file+'.docx'"

There is no other way to read .doc file properly that worked for me other than antiword.

JaySabir
  • 322
  • 1
  • 10
  • I have also tried running directly on the terminal using bash loop and it doesn't work either - it just changes the file size to 0 bytes – JaySabir May 11 '20 at 06:40

1 Answers1

0

Subprocess doesn't run bash. So run bash and pass arguments with arguments remembering about proper quoting.

subprocess.run(["bash", "-c", "antiword \"$1\" > \"$1\".docx", "_", file])
KamilCuk
  • 120,984
  • 8
  • 59
  • 111