【发布时间】:2014-03-26 11:02:34
【问题描述】:
我正在尝试通过stdin 传递数据来执行 Inkscape。 Inkscape 仅通过 /dev/stdin 支持此功能。基本上,我正在尝试做这样的事情:
echo "<sgv>...</svg>" | inkscape -z -f /dev/stdin -A /dev/stdout
我不想将 SVG 写入磁盘。
我尝试只使用stdin.write(),但它不起作用(可能是因为/dev/stdin):
var cmd = spawn("inkscape", ["-z", "-f", "/dev/stdin", "-A", "/dev/stdout"], {encoding: "buffer", stdio: ["pipe", stdoutPipe, "pipe"]});
cmd.stdin.write(svg);
这确实有效,但我必须将 SVG 写入磁盘:
var cmd = spawn("inkscape", ["-z", "-f", "/dev/stdin", "-A", "/dev/stdout"], {encoding: "buffer", stdio: [fs.openSync('file.svg', "a"), stdoutPipe, "pipe"]});
我尝试将流传递给stdio,但我不断收到TypeError: Incorrect value for stdio stream: [object Object]
有什么想法吗?
附录
示例使用 Inkscape,但我的问题适用于任何使用 /dev/stdin 的任意程序。
顺便说一句,这对我有用:
var exec = require('child_process').exec;
exec("echo \"<svg>...</svg>\" | inkscape -z -f /dev/stdin -A /dev/stdout | cat", function (error, stdout, stderr) {});
不过,我的 SVG 太长了,所以报错:Error: spawn Unknown system errno 7
【问题讨论】:
标签: node.js