2012-01-05 281 views
0

我无法弄清楚我需要为ImageMagick放置文件来处理它们。我试图在我的ASP.NET MVC网站中使用它,并没有找到我的文件进行处理。如果它确实如何指定它们的输出位置?imagemagick文件路径?获取'系统找不到指定的文件错误'

我一直在这里寻找和我MUT失去了一些东西: http://www.imagemagick.org/script/command-line-processing.php

这里是我的代码调用过程:

//Location of the ImageMagick applications 
     private const string pathImageMagick = @"C:\Program Files\ImageMagick-6.7.3-8"; 
     private const string appImageMagick = "MagickCMD.exe"; 

CallImageMagick("convert -density 400 SampleCtalog.pdf -scale 2000x1000 hi-res%d.jpg"); 


private static string CallImageMagick(string fileArgs) 
     { 
      ProcessStartInfo startInfo = new ProcessStartInfo 
      { 
       Arguments = fileArgs, 
       WorkingDirectory = pathImageMagick, 
       FileName = appImageMagick, 
       UseShellExecute = false, 
       CreateNoWindow = true, 
       RedirectStandardOutput = true 
      }; 
      using (Process exeProcess = Process.Start(startInfo)) 
      { 
       string IMResponse = exeProcess.StandardOutput.ReadToEnd(); 
       exeProcess.WaitForExit(); 
       exeProcess.Close(); 
       return !String.IsNullOrEmpty(IMResponse) ? IMResponse : "True"; 
      } 
     } 

回答

1

我们做同样的事情,但使用环境变量(这是因为它可以在每个系统上运行)来执行我们提供的convert和参数的cmd.exe。这是我们如何创建ProcessStartInfo对象:

// Your command 
string command = "convert..."; 

ProcessStartInfo procStartInfo = new ProcessStartInfo {CreateNoWindow = true}; 
string fileName = Environment.GetEnvironmentVariable("ComSpec"); 
if (String.IsNullOrEmpty(fileName)) 
{ 
    // The "ComSpec" environment variable is not present 
    fileName = Environment.GetEnvironmentVariable("SystemRoot"); 
    if (!String.IsNullOrEmpty(fileName)) 
    { 
     // Try "%SystemRoot%\system32\cmd.exe" 
     fileName = Path.Combine(Path.Combine(fileName, "system32"), "cmd.exe"); 
    } 
    if ((String.IsNullOrEmpty(fileName)) || (!File.Exists(fileName))) 
    { 
     // If the comd.exe is not present, let Windows try to find it 
     fileName = "cmd"; 
    } 
} 
procStartInfo.FileName = fileName; 
procStartInfo.RedirectStandardInput = true; 
procStartInfo.RedirectStandardOutput = true; 
procStartInfo.UseShellExecute = false; 
Process proc = Process.Start(procStartInfo); 

proc.StandardInput.WriteLine(command); 
proc.StandardInput.Flush(); 

然后我们从proc.StandardOutput为了得到错误信息和结果代码读取。之后,我们销毁这些物品。

对不起,如果这不是100%,我复制它从一个更复杂的OO代码。

相关问题