简体   繁体   中英

Why my process just opens a blank window and closes it immediately?

I am trying to call convert.exe trough Process class from C# to convert a specific image to another format like this:

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();

I do not understand why it opens a command prompt and shuts it down immediately...Do you see any error in the code? The path to convert.exe is fine for sure...

You web application is running in the context of the IIS user, it may not have access to execute convert.exe. You could either try running IIS under a specific user (like you, if convert.exe works for you) or grant access in some way to let convert.exe run).

You can attach a Stream to the Process object to capture the output.

see the msdn doc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM