1

I am using Inkscape to take an input single page pdf file and to output an svg file. The following works from the command line

c:\progra~1\Inkscape\inkscape -z -f "N:\pdf_skunkworks\inflation-report-may-2018-page0.pdf" -l "N:\pdf_skunkworks\inflation-report-may-2018-page0.svg"

where -z is short for --without-gui, -f is short for input file, -l is short for --export-plain-svg. And that works from command line.

I could not get the equivalent to work from Python, either passing the command line as one long string or as separate arguments. stderr and stdout give no error as they both print None

import subprocess #import call,subprocess #completed = subprocess.run(["c:\Progra~1\Inkscape\Inkscape.exe",r"-z -f \"N:\pdf_skunkworks\inflation-report-may-2018-page0.pdf\" -l \"N:\pdf_skunkworks\inflation-report-may-2018-page0.svg\""]) completed = subprocess.run(["c:\Progra~1\Inkscape\Inkscape.exe","-z", r"-f \"N:\pdf_skunkworks\inflation-report-may-2018-page0.pdf\"" , r"-l \"N:\pdf_skunkworks\inflation-report-may-2018-page0.svg\""]) print ("stderr:" + str(completed.stderr)) print ("stdout:" + str(completed.stdout)) 

Just to test OS plumbing I wrote some VBA code (my normal language) and this works

Sub TestShellToInkscape() '* Tools->References->Windows Script Host Object Model (IWshRuntimeLibrary) Dim sCmd As String sCmd = "c:\progra~1\Inkscape\inkscape -z -f ""N:\pdf_skunkworks\inflation-report-may-2018-page0.pdf"" -l ""N:\pdf_skunkworks\inflation-report-may-2018-page0.svg""" Debug.Print sCmd Dim oWshShell As IWshRuntimeLibrary.WshShell Set oWshShell = New IWshRuntimeLibrary.WshShell Dim lProc As Long lProc = oWshShell.Run(sCmd, 0, True) End Sub 

So I'm obviously doing something silly in the Python code. I'm sure experienced Python programmer could solve easily.

2
  • it's possible your process is not even running, no exception is being surfaced? can you try Popen and communicate? like here Commented Jun 18, 2018 at 18:33
  • 1
    @Srini: thanks for feedback. Thanks to you I ran SysInternals Process Monitor to check the "spawn stack". This helped me diagnose the command line and along with JacobIRR's suggestion helped me solve. Commented Jun 18, 2018 at 19:11

1 Answer 1

2

Swap your slashes:

import subprocess #import call,subprocess completed = subprocess.run(['c:/Progra~1/Inkscape/Inkscape.exe', '-z', '-f', r'N:/pdf_skunkworks/inflation-report-may-2018-page0.pdf' , '-l', r'N:/pdf_skunkworks/inflation-report-may-2018-page0.svg']) print ("stderr:" + str(completed.stderr)) print ("stdout:" + str(completed.stdout)) 

Python knows to swap forward slashes for back slashes on windows OS, and your back slashes are currently acting as escape prefixes.

Sign up to request clarification or add additional context in comments.

1 Comment

You put me on the right track, I've pasted working code into this answer. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.