On Windows you won't have much fun with Inkscape's command line options. They do work just fine, but you won't see any feedback messages. While the messages are written to stdout and stderr, these streams aren't connected to anything. And all that eventually useful information is flushed down the virtual toilet.
(If you aren't interested in the details skip over to InkCL.bat usage and the zip package.)
That's just how things are with Windows - either spawn a cmd.exe window or get nothing. Getting some extra cmd window each time you use Inkscape would be a tad annoying, therefore the other option was chosen. Java solves it with two executables: java.exe and javaw.exe (where the former spawns a cmd window and the latter doesn't).
In Java's case they are tiny wrappers. Inkscape is a lot bigger tho, therefore that wouldn't be the smartest thing to do. ~6.7mb just for better command line support? Naaah. However, a tiny separate wrapper program, which just spawns Inkscape.exe as child process would work fine. Ultimately it's the best option and most likely the one we'll pick.
As a temporary solution for the time being you can use the following Python program. It hands the command line arguments over to Inkscape and grabs the stdout and stderr streams and prints 'em on screen.
InkCL.py (place it in the same directory as inkscape.exe)
#!/opt/oss/bin/python
import os, subprocess, sys
def spawn():
cmd=sys.argv
cmd.pop(0)
cmd.insert(0,'inkscape')
run=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err=[e.splitlines() for e in run.communicate()]
return run.returncode, out, err
if __name__=='__main__':
r=spawn()
if not r[0]==0:
print 'return code:',r[0]
for l in r[1]:
print l
for l in r[2]:
print lInkCL.py usage:
python InkCL.py <inkscape options>
PNG export example:
C:\Inkscape-0.45.1-1\inkscape>python InkCL.py -e image.png ext.svg Background RRGGBBAA: ffffff00 Area 0:0:64:64 exported to 64 x 64 pixels (90 dpi) Bitmap saved as: image.png
If you don't have Python installed. Fear not! Inkscape is actually shipped with a Python interpreter, which is used by many extensions. We can use this interpreter and also shorten the command line by using a batch file.
InkCL.bat (place it in the same directory as inkscape.exe)
@"./python/python.exe" InkCL.py %*
InkCL.bat usage:
InkCL.bat <inkscape options>
The following also works:
inkcl <inkscape options>
PNG export example:
C:\Inkscape-0.45.1-1\inkscape>inkcl -e image.png ext.svg Background RRGGBBAA: ffffff00 Area 0:0:64:64 exported to 64 x 64 pixels (90 dpi) Bitmap saved as: image.png
Download: inkscape_win32_command_line.zip (1kb - contains: InkCL.py, InkCL.bat, and a readme)
Update: See inkscapec.exe - A Command Line Wrapper for Win32 for a better solution.
Comments
Talk About Timely!
Needed this tonight and bang! Just like that posted 5 days ago.
Thanks a lot! Saved me sooooo much time.
Post new comment