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.

S Meaden
  • 8,050
  • 3
  • 34
  • 65
  • it's possible your process is not even running, no exception is being surfaced? can you try `Popen` and `communicate`? like [here](https://stackoverflow.com/questions/912830/using-subprocess-to-run-python-script-on-windows) – Srini Jun 18 '18 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. – S Meaden Jun 18 '18 at 19:11

1 Answers1

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.

S Meaden
  • 8,050
  • 3
  • 34
  • 65
JacobIRR
  • 8,545
  • 8
  • 39
  • 68