Search code examples
batch-filecygwininkscape

Cygwin terminal batch file - cannot find file, but can if I run the cmd myself it does


Under cygwin I created to_png.bat and just filled it with inkscape command lines used to convert my SVG files to PNG. If I run these commands myself on the command line they will execute successfully. If I run the to_png.bat file I get the following error:

** (inkscape.exe:3856): WARNING **: Specified document 'svgs/ace.svg' cannot be opened (does not exist or not a valid SVG file)

I am running from the same directory of course and I also tried specifying the absolute path in case somehow the working directory inkscape saw was different when running the .bat file. I just did this using python and os.system calls and had the same problem.

EDIT: Running from a dos command line fails as well with the same problem. Finds inkscape on the PATH, but inkscape cannot find the .svg file. Is this a problem with the single quotes? I have file names with spaces in them hence the quoting.

to_png.bat:

inkscape -h 120 -e 'pngs/ace.png' 'svgs/ace.svg'
inkscape -h 120 -e 'pngs/king.png' 'svgs/king.svg'
inkscape -w 120 -e 'pngs/queen.png' 'svgs/queen.svg'

Solution

  • In Windows batch scripting, the ' character is not recognised as a character for delimiting file names. Instead, " is used. Also, you would probably be better off using backslashes instead of forward slashes as path delimiters.

    Thus, your script should probably look like this:

    inkscape -h 120 -e "pngs\ace.png" "svgs\ace.svg"
    inkscape -h 120 -e "pngs\king.png" "svgs\king.svg"
    inkscape -w 120 -e "pngs\queen.png" "svgs\queen.svg"