【发布时间】:2014-10-05 19:21:45
【问题描述】:
我尝试了不同的配置,但我似乎无法在 node.js 环境中成功执行“gs”(Ghostscript)。
var fs = require( "fs" ),
child_process = require( 'child_process' );
...
var spawn = child_process.spawn;
var opts = [
"-q ",
"-dQUIET ",
"-dSAFER ",
"-dBATCH ",
"-dNOPAUSE ",
"-dNOPROMPT ",
"-dMaxBitmap=500000000 ",
"-dAlignToPixels=0 ",
"-dGridFitTT=2 ",
"-sDEVICE=jpeg ",
"-dTextAlphaBits=4 ",
"-dGraphicsAlphaBits=4 ",
"-r150 ",
"-sOutputFile=afile.jpg",
" afile.pdf"
];
var gs = spawn( "gs", opts, { cwd: "/mnt/drive/" } );
gs.stdout.on( 'data', function( data ) {
console.log( 'stdout: ' + data );
} );
gs.stderr.on( 'data', function( data ) {
console.log( 'stderr: ' + data );
} );
gs.on( 'close', function( code ) {
console.log( 'child process exited with code ' + code );
} );
---输出 ---------------------------------------- -----------------
stdout: Unknown device: jpeg
stdout: Unrecoverable error: undefined
stdout: in .uninstallpagedevice
stdout: Operand stack:
defaultdevice
stdout:
child process exited with code 1
------------------------------------------ -----------------------
/mnt/drive 目录对所有用户都是 +read+write。 gs -help 执行返回:
root@Machine:/# gs -help
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
Usage: gs [switches] [file1.ps file2.ps ...]
Most frequently used switches: (you can use # in place of =)
-dNOPAUSE no pause after page | -q `quiet', fewer messages
-g<width>x<height> page size in pixels | -r<res> pixels/inch resolution
-sDEVICE=<devname> select device | -dBATCH exit after last file
-sOutputFile=<file> select output file: - for stdout, |command for pipe,
embed %d or %ld for page #
Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF
Default output device: bbox
Available devices:
...
ijs imagen inferno inkcov iwhi iwlo iwlq jetp3852 jj100 jpeg jpegcmyk
jpeggray la50 la70 la75 la75plus laserjet lbp310 lbp320 lbp8 lex2050
...
txtwrite uniprint xcf xes
Search path:
/usr/share/ghostscript/9.05/Resource/Init :
/usr/share/ghostscript/9.05/lib :
/usr/share/ghostscript/9.05/Resource/Font :
/usr/share/ghostscript/fonts : /var/lib/ghostscript/fonts :
/usr/share/cups/fonts : /usr/share/ghostscript/fonts :
/usr/local/lib/ghostscript/fonts : /usr/share/fonts
For more information, see /usr/share/doc/ghostscript/Use.htm.
Please report bugs to bugs.ghostscript.com.
root@Machine:/#
设备 jpeg 可用的地方。 gs 执行未执行。任何提示都会有所帮助?
【问题讨论】:
-
愚蠢的问题:如果您在 cmd 行上运行完全相同的 cmd 会发生什么?
Unknown device: jpeg似乎是一个 gs 错误(虽然是stdout?).. -
不傻,我没有对那个测试发表评论,但是是的,它确实适用于 linux 行上的这个命令。
-
有关信息,我将
-sOutputFile=afile.jpg更改为 png 扩展名,而-sDEVICE=png256没有运气。相同的“未知设备”。 -
也许节点以不同的用户、chroot 或沙箱的身份运行子进程?老实说,我不知道。也许人们知道的ghostscript。它是否适用于 cronjob 等?
-
@Rudie,node.js 代码以与用于在 shell 命令上测试成功的原始命令的用户 ID 相同的用户启动。
标签: javascript node.js process ghostscript spawn