tags:

views:

703

answers:

1

Hi,

When I open a command window in windows and use the imagemagick convert command:

convert /somedir/Garden.jpg /somedir/Garden.png

It works as expected.

What I am trying to do is executing the same command as above using C#.

I tried using System.Diagnostics.Process, however, no foo.png gets created.

I am using this code:

      var proc = new Process
      {
          StartInfo =
          {
              Arguments = string.Format("{0}Garden.jpg {1}Garden.png",
              TEST_FILE_DIR,
              TEST_FILE_DIR),
              FileName = @"C:\xampp\ImageMagick-6.5.4-Q16\convert",
              UseShellExecute = false,
              CreateNoWindow = true,
              RedirectStandardOutput = false,
              RedirectStandardError = false
          }
      };

      proc.Start();

No exception gets thrown, but no .png is written, either.

+1  A: 

My guess is that TEST_FILE_DIR contains a space - so you have to quote it.

Try this:

Arguments = string.Format("\"{0}Garden.jpg\" \"{1}Garden.png\"",
                          TEST_FILE_DIR,
                          TEST_FILE_DIR)

You might also want to give the filename including the extension, e.g.

FileName = @"C:\xampp\ImageMagick-6.5.4-Q16\convert.exe"
Jon Skeet
That worked, thank you! You just put quotes around the arguments, right?
Yup - just to cope with spaces.
Jon Skeet