1

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'
3
  • 1
    Do you need those quotes around the filenames?
    – Gabe
    Jul 31, 2011 at 14:05
  • how would a filename with spaces in it be handled without using quotes? I have some like "ace green.svg" which necessitated the quoting.
    – user317033
    Jul 31, 2011 at 14:22
  • 2
    @Mark: Yes, but the quotation marks in batch scripts should be ", not '.
    – Andriy M
    Jul 31, 2011 at 14:36

5 Answers 5

2

What you are trying to do is fundamentally weird.

Since you have bash, you could simply make a shell script and run exactly the same commands that you type at the shell prompt.

Instead, you are trying to make a .bat file which is run by cmd.exe using its own PATH and environment. Why?

If you really must do this, start out by running cmd to open a Windows command prompt, then test your commands (and PATH) variable until you can get it to work right. You will definitely be changing either the PATH variable or the command lines, or both. But if you can run it from a Windows command prompt, then you will be able to just copy those command lines into a .bat file and run them.

1

The directory separator in DOS/Windows is a backslash. So using a slash may work under the cygwin shell but not in a .bat.

1
  • It works with double quotes " so I assume it passes it to inkscape as-is when quoted and inkscape handles the forward slash correctly.
    – user317033
    Jul 31, 2011 at 14:44
0

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"
2
  • Windows CMD.EXE does not preprocess command lines in the same way as UNIX. Therefore it is entirely possible that inkscape, whose origin is UNIX, requires a regular slash (/) on those pathnames, even if you run it from the CMD.EXE prompt with no Cygwin at all. Aug 7, 2011 at 6:00
  • That is one area I am little acquainted with so far (working with commands that, although ported to Windows, process their command line arguments in a way they do it in UNIX), therefore I can't argue with that. Thanks for pointing it out to me.
    – Andriy M
    Aug 7, 2011 at 8:33
0

I think it's passing paths with forward slashes to windows commands doesn't always work.

0

Replacing the single tick ' with double ticks " solved the problem and allowed for spaces in the filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.