8

Possible Duplicate:
Calling an external command in Python

I am trying to convert SVG files to PDFs in Python. I want to use Inkscape for this. How can I call Inkscape in Python ?

Community
  • 1
  • 1
medusalith
  • 141
  • 1
  • 3
  • http://www.whathaveyoutried.com – BrtH Jul 25 '12 at 15:10
  • Hi there. We like to see a bit of prior research before questions are asked here, and - ideally - a bit of code to go with the problem. I'd wager that "system command python" in a search engine would get you what you need. – halfer Jul 25 '12 at 19:26
  • sorry i am new with python ,i searched for 'svg to pdf in python ', but i couldn't find any answers.Anyway thanks for advice. – medusalith Jul 26 '12 at 06:16

1 Answers1

3

If you don't need to communicate with the process at all, this should do just fine:

import subprocess
p=subprocess.call(['program','arg1','arg2','arg3', ...])
mgilson
  • 264,617
  • 51
  • 541
  • 636
  • what should i use for arguments?I mean , are the arguments becoming paths of svg files when i use inkspace ? – medusalith Jul 26 '12 at 06:18
  • I try to use like `p = subprocess('/usr/bin/inkspace','file1.svg','file2.pdf')` but it gives me an error like : `'module' pbject is not callable` – medusalith Jul 26 '12 at 07:17
  • @user1351130 -- Try this: `p=subprocess.call(['/usr/bin/inkscape','file1.svg','file2.pdf'])` – mgilson Jul 26 '12 at 12:26
  • ok, thank you ,but i used this and it works to : `p=subprocess['/usr/bin/inkscape', 'file1.svg', '--export-pdf', 'file2.pdf']` – medusalith Jul 30 '12 at 07:32
  • @medusalith: Look at Python's shlex.split() method. It will split a single command string into proper arguments. – Iron Pillow Aug 06 '14 at 23:27
  • Using `/usr/bin/inkscape` is not portable; Python should already be aware of your `PATH` so use plain `inkscape` as the argument instead. If that doesn't work, it's safer to add `/usr/bin/` to your `PATH` then to force one location on all users. – NuclearPeon Dec 21 '15 at 23:04