Command Line Usage in Windows

Post questions on how to use or achieve an effect in Inkscape.
gsal
Posts: 2
Joined: Fri Jan 08, 2010 9:04 pm

Command Line Usage in Windows

Postby gsal » Fri Jan 08, 2010 9:24 pm

Attempted to run inkscape at the DOS prompt with the following command:

Code: Select all

inkscape -f legend.svg -A legend.pdf

but did not work, nor gave any error message.

Wrote the following python code to catch stdout and stderr:

Code: Select all

import subprocess

cmd = "c:\programs\editors\graphical\inkscape\inkscape.exe -f legend.svg -A legend.pdf"
proc = subprocess.Popen(cmd, shell=True,
                        stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
                        )
stdout_value,stderr_value = proc.communicate()
print "Standard Output follows:"
print stdout_value
print "Standard Error follows:"
print stderr_value

Executed python script and received the following message:

Code: Select all

Standard Output follows:

** (inkscape.exe:1572): CRITICAL **:
Inkscape::XML::Document* sp_repr_read_file(const gchar*, const gchar*):
assertion `Inkscape::IO::file_test( filename, G_FILE_TEST_EXISTS )' failed

** (inkscape.exe:1572): CRITICAL **:
Inkscape::XML::Document* sp_repr_read_file(const gchar*, const gchar*):
assertion `Inkscape::IO::file_test( filename, G_FILE_TEST_EXISTS )' failed

** (inkscape.exe:1572): WARNING **: Specified document legend.svg cannot be
opened (does not exist or not a valid SVG file)

Standard Error follows:
None

But as far as I can tell legend.svg is a perfectly fine file that can be open with inkscape and actually saved as *pdf file, too. I just would like to automate this and do it programatically.

Any ideas? I would appreciate any pointers.

Thanks,

gsal

User avatar
sas
Posts: 404
Joined: Sat Oct 06, 2007 5:42 am

Re: Command Line Usage in Windows

Postby sas » Sat Jan 09, 2010 2:17 am

It seems to think that the current directory is the directory where inkscape.exe is. So you need to give the full path for both files.

gsal
Posts: 2
Joined: Fri Jan 08, 2010 9:04 pm

Re: Command Line Usage in Windows

Postby gsal » Sat Jan 09, 2010 4:57 am

You are correct. Thanks.

That is silly or, rather, wrong and needs to be fixed. I mean, if I am at the command line in some directory of mine where I keep my files and want to edit one of them, I simply type the name of my favorite editor followed by the name (and not the entire path to it) of the file that I want to edit and that's it...the editor launches and automatically loads the file of interest. Inkscape, at it is, fails to work this way...you give it a file name and fails to find it, precisely because it seems to look in the same directory where it is installed and not the one it was launched from...I think this is a bug.

Thanks again, though.

gsal

User avatar
sas
Posts: 404
Joined: Sat Oct 06, 2007 5:42 am

Re: Command Line Usage in Windows

Postby sas » Sat Jan 09, 2010 5:16 am

Yes, it's a bug: bug 504713. It only happens under Windows.

skvalen
Posts: 2
Joined: Tue Apr 06, 2010 7:11 pm

Re: Command Line Usage in Windows

Postby skvalen » Thu Apr 08, 2010 10:13 pm

This is a nice workaround:

Code: Select all

c:\path\to\inkscape.exe -f "%CD%\legend.svg" -A "%CD%\legend.pdf"



this is also a nice trick :)

Code: Select all

FOR %? IN (*.svg) DO c:\path\to\inkscape.exe -f "%CD%\%?" -A "%CD%\%?.pdf"



%CD% is a equivalent to pwd in *nix

skvalen
Posts: 2
Joined: Tue Apr 06, 2010 7:11 pm

Re: Command Line Usage in Windows

Postby skvalen » Thu Apr 08, 2010 10:35 pm

This is a nice workaround:

Code: Select all

c:\path\to\inkscape.exe -f "%CD%\legend.svg" -A "%CD%\legend.pdf"



this is also a nice trick :)

Code: Select all

FOR %? IN (*.svg) DO c:\path\to\inkscape.exe -f "%CD%\%?" -A "%CD%\%?.pdf"



%CD% is a equivalent to pwd in *nix

User avatar
sphaira
Posts: 9
Joined: Sun Apr 25, 2010 9:14 pm

Re: Command Line Usage in Windows

Postby sphaira » Sat May 01, 2010 4:14 am

Maybe this script can help anyone,

I created this script to use in a cygwin environment with inkscape for windows. I also tested with python for windows. The script works in the major part of the case except for the command --shell.

You have to add inkscape path to the variable %PATH%. it is used by calling inkscape.exe with the arguments you pass to the script. I'm french so i have write a print function to décode UTF-8 text.

example of usage:

Code: Select all

inkscape.py --verb-list


Code: Select all

import os, subprocess, sys, codecs

OUT_STR_CODE="ISO-8859-1"

# Le chemin courant
WORK_PATH=os.getcwd()

## Affichage UTF-8 dans la console
def _print(msg):
    try:
        out=unicode( str(msg), OUT_STR_CODE )
    except:
        out=msg
    print out
   
def do():
    cmd=sys.argv
    cmd.pop(0)

    # Le programe inkscape
    # Le chemin de inkscape doit être plcé dans $PATH
    cmd.insert(0,'inkscape.exe')
    # Evite que inkscape GUI démarre
    cmd.append('--without-gui')

    run=subprocess.Popen(
        cmd,
        shell=False,
        cwd=WORK_PATH,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
   
    # Renvoie les messages de inkscape dans la console
    out,err=[e.splitlines() for e in run.communicate()]
   
    # Retour du code de inkscape
    return run.returncode, out, err

if __name__=='__main__':
    r=do()
    if not r[0]==0:
        _print( 'return code:' + r[0] )
    for l in r[1]:
        _print(l)
    for l in r[2]:
        _print(l)


enjoy :D ! (and perhaps debug :( )


Return to “Help with using Inkscape”