Ghostscript崩溃了服务器

时间:2012-09-10 06:53:33

标签: c# asp.net iis-7.5 ghostscript cassini

我的问题是:我使用ghostscript将一些pdf转换为jpeg文件,然后将它们渲染为silverlight控件。我正在使用:

转换pdf文件
public void PdfToJpg(string ghostScriptPath, string input, string output) {
            timer1.Enabled = true;
            //if the pdf has more than 1 file (ex. 3) then 3 jpeg files will be outputed 
            String ars = "-dNOPAUSE -sDEVICE=jpeg  -r300 -o" + output + "-%d.jpeg  " + input;
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.Arguments = ars;
            startInfo.FileName = ghostScriptPath;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;            
            using (Process exeProcess = Process.Start(startInfo)) {
                exeProcess.WaitForExit();
            }           
        }

然后将页码和页面字节[]保存到会话中的字典,字典中并使用启用Silverlight的服务发送它,并将它们发送到包含silverlight控件的aspx页面(使用Response.redirect(第1页)。 ASPX))。一切运行良好但有时服务器(Cassini或IIS)崩溃,这意味着文件被转换但重定向永远不会发生,只是页面保持加载状态。我必须使用“结束进程”关闭cassini或重新启动IIS服务器,以便该进程再次运行。我认为问题不在于服务,因为我有一个类似的过程发送到silverlight aplication一个byte []的音频文件,一切正常,服务器永远不会卡住,所以我认为这是因为ghostscript ..如果有人讨厌想法。此外,我正在使用elmah并且没有报告错误...并且在调试时,当我单击包含转换和该过程的其他部分的视图按钮时,它不会进入单击事件但转换已完成(不是重定向),我不知道怎么可能......谢谢。所以肯定是ghostscript的东西

更新: 我将我的代码更改为:

     using (Process convertProc = new Process()) {
                convertProc.StartInfo.FileName = ghostScriptPath;
                convertProc.StartInfo.Arguments = args;
                //convertProc.StartInfo.UseShellExecute = false;
                //convertProc.StartInfo.RedirectStandardOutput = true;
                convertProc.StartInfo.CreateNoWindow = true;
                convertProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                convertProc.Start();
                ThreadedKill(convertProc.Id);
                convertProc.PriorityClass = ProcessPriorityClass.Normal;
                convertProc.WaitForExit();
                }

如果useshellexecute和redirectoutput被注释,服务器有时会“疯狂”,如果没有,代码每次运行都很完美,但是这样,ghostscript进程的窗口出现了,我不希望这样。为了不出现我必须评论这一行或将useshellexecute设置为true并注释redirectoutput,这有时会导致失败。我能做什么?什么是redirectStandardOutput以及它是什么......,在MSDN上不明白......

更新2: 将我的gswin64.exe更改为gswin64c.exe以用于控制台应用程序,现在我正在谈论的那个窗口不再显示了。没有代码疯了......至少还没有......

1 个答案:

答案 0 :(得分:1)

首先,您不需要-dNOPAUSE,因为-o隐含-dBATCH-dNOPAUSE但不会受到伤害。

这个问题是否“间歇性”发生?或者,如果您重复发送一个挂起(崩溃服务器?)的文件:它是每次都挂起,还是更频繁地挂起该特定文件?

如果这是真正间歇性的,则不太可能是Ghostscript。

要将 stdout stderr 从Ghostscript捕获到文件中,您可以添加-sstdout=___.out-sstderr=___.err以查看Ghostscript是否有抱怨。如果您总是编写相同的文件,错误后的内容将告诉您gswin * .exe是否生成了任何消息。

添加-Z:也会为Ghostscript输出添加一些计时信息。

请注意,由于您使用-r300进行JPEG输出:如果Ghostscript意外停止, TEMP 目录中将有两个以te_开头且具有的文件.tmp扩展程序。这些是为用于绑定的基于磁盘的“clist”文件创建的(300 dpi字母大小的页面足够大,超过默认-dMaxBitmap=____值8m)。

如果在TEMP文件夹中没有看到te_XXXXX.tmp个文件的累积,那么Ghostscript(可能)不会崩溃。