开发者

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'
inkscap开发者_如何转开发e -w 120 -e 'pngs/queen.png' 'svgs/queen.svg'


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.


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


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"


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜