0

I would like to write a python script to automate the conversion of libreoffice ott templates to normal odt files. if I go to the terminal (bash shell) and I type:

soffice --headless --convert-to odt "/path/template.ott" --outdir '/targetpath/template.odt'

The output is as expected, an odt file in a new target location.

When I script it (like so:

oldfile
outdir = pipes.quote(/targetpath/template.odt)
subprocess.call(['soffice --headless --convert-to odt /path/template.ott --outdir /pathtarget/template.odt'])

the output gives me

[Errno 2] No such file or directory

When I try to make the call like this:

subprocess.call(["soffice", "--headless", "--convert-to", "odt", pipes.quote(oldpath),outdir])

The result is the helptext of soffice, with the the reason:

    LibreOffice 4.2.8.2 420m0(Build:2)

    Unknown option: --outdir /targetpath/template.odt
...
River
  • 8,585
  • 14
  • 54
  • 67
Tom
  • 3
  • 3
  • Have you tried adding shell=True to the subprocess call? – kezzos Jun 21 '16 at 11:08
  • Indeed, for passing the command as one string, adding shell=True is a solution! thanks alot. It was indeed an allready answered question (http://stackoverflow.com/questions/18962785/oserror-errno-2-no-such-file-or-directory-while-using-python-subprocess-in-dj). However, I still cannot get it to work with the list, Again, indeed that bug was mentioned in http://stackoverflow.com/questions/15109665/subprocess-call-using-string-vs-using-list. – Tom Jun 22 '16 at 07:45

1 Answers1

-1

Why not try with os.system ?

os.system('soffice --headless --convert-to odt "/path/template.ott" --outdir "/targetpath/template.odt"')
Teemo
  • 449
  • 6
  • 23