我希望有人可以帮助解决这个问题,因为我自己没有得到它。
我编译了最新版本的pdf2swf,一切都运行得很好,除了我想在NodeJS中使用它作为衍生的child_process。
当我使用与exec相同的命令时,它再次工作。提供一些代码示例:
// convert a pdf to swf using exec (works)
var tmpSwfLocation = docsDir+'/Paper.pdf.swf';
var pdf2swf = cp.exec('pdf2swf '+tmpPDFLocation+' -o '+tmpSwfLocation+' -G -v -f -T 9 -t -j '+quality+' -s subpixels='+resolution+' -s storeallcharacters -s poly2bitmap', function(err, stdout, stderr){
console.log(stdout);
console.log(stderr);
var end = Date.now();
console.log('pdf2swf: SWF created in '+((end-start) /1000)+' seconds');
});
// convert a pdf to swf (does not work)
var tmpSwfLocation = docsDir+'/Paper.pdf.swf';
var pdf2swf = cp.spawn('pdf2swf', ['-G','-v','-f','-T 9', '-t', '-j '+quality,'-s subpixels='+resolution,'-s storeallcharacters', '-s poly2bitmap',tmpPDFLocation, '-o '+tmpSwfLocation],{setsid:true});
pdf2swf.stdout.on('data',function(output){
console.log("pdf2swf:"+output)
});
pdf2swf.stderr.on('data',function(output){
console.log("pdf2swf ERROR:"+output);
});
pdf2swf.stdout.on('end', function(output){
var end = Date.now();
console.log('pdf2swf: SWF created in '+((end-start) /1000)+' seconds');
});当child_process尝试将数据写入文件时,衍生进程会在最后中断:
pdf2swf:NOTICE Writing SWF file /home/bitnami/flipdoc/ec2-instances/worker/pdf_test/test_directory/test-Testfile_31MB_26Pages.pdf_0/docs/Paper.pdf.swf
pdf2swf:FATAL Could not create " /home/bitnami/flipdoc/ec2-instances/worker/pdf_test/test_directory/test-Testfile_31MB_26Pages.pdf_0/docs/Paper.pdf.swf". 使用exec,该过程使用以下命令成功完成:
pdf2swf:NOTICE Writing SWF file /home/bitnami/flipdoc/ec2-instances/worker/pdf_test/test_directory/test-Testfile_31MB_26Pages.pdf_0/docs/Paper.pdf.swf和一个存在的文件。
附加信息:在整个过程之前,我对整个"test_directory“执行递归chmod777。
问候
发布于 2012-08-24 19:20:14
我自己解决的..。永远不会(想都不要想……)在派生进程的参数中使用空格。如果你有一个可以在其间使用空格的param=value参数,只需将它们与其他参数一起排在数组中即可。
上面的spawn的源代码现在看起来像这样:
var pdf2swf = cp.spawn('pdf2swf', [tmpPDFLocation, '-o',tmpSwfLocation,'-G','-vvv','-f','-T','9', '-t', '-j',quality,'-s','subpixels='+resolution,'-s','storeallcharacters', '-s','poly2bitmap']);https://stackoverflow.com/questions/12076310
复制相似问题