为什么我的进程只是打开一个空白窗口并立即关闭它

本文关键字:窗口 空白 一个 进程 我的 为什么 | 更新日期: 2023-09-27 18:36:40

我正在尝试从 C# 调用 convert.exe 通过 Process 类将特定图像转换为另一种格式,如下所示:

File.WriteAllBytes(inputFilePath, Convert.FromBase64String(image.Content));
Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new Exception("Succesfully wrote the image to: " + inputFilePath)));
var proc = new Process();
proc.StartInfo.Arguments = string.Format("{0} {1}", inputFilePath, outputFilePath);
proc.StartInfo.FileName = @"c:'Program Files (x86)'ImageMagick-6.7.7-Q16'convert.exe";
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();

我不明白为什么它会打开命令提示符并立即关闭它......您是否在代码中看到任何错误?转换的路径.exe肯定很好...

为什么我的进程只是打开一个空白窗口并立即关闭它

您的 Web 应用程序正在 IIS 用户的上下文中运行,它可能无权执行转换.exe。 您可以尝试在特定用户下运行 IIS(例如您,如果转换.exe适合您),或者以某种方式授予访问权限以让转换.exe运行)。

可以将流附加到进程对象以捕获输出。

请参阅 MSDN 文档