0

I am trying to extract thumbnail from a indd file using c#.

I can execute the following command from commandline, which works fine

exiftool -r -b -PageImage sample.indd > sample.jpg

but when I tried it from my c# project its not producing the output file

My sample code

string c_arguments = string.Format("-r -b -PageImage {0} > {1}", _DirectoryPath + "\\" +  fileName, 
_DirectoryPath + "\\output.jpg");
var psi = new ProcessStartInfo("exiftool.exe", c_arguments);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;

try
{
  using (Process exeProcess = Process.Start(psi))
  {
    exeProcess.Start();
    Console.WriteLine("Executed successfully");
  }
}
catch (Exception ex)
{
   Console.WriteLine("Error occured, ErrorMsg: " + ex.Message);
}

after exeProcess.Start(), is executed the program waits forever no output is produced.

What am I missing here.

ony19161
  • 73
  • 8

1 Answers1

1

The > sample.jpg part of your example command line is a shell redirect and is a function of the shell/terminal/CMD that you are using. It is not available when starting exiftool from your program (see this related StackOverflow answer).

You might look into the -w (-textout) option. See this example command, which is more complex than what you need, but should provide help creating the command you need.

StarGeek
  • 4,948
  • 2
  • 19
  • 30
  • thanks for your suggestion, after i removed "> sample.jpg", and added exeProcess.OutputDataReceived += OutputDataReceived; the above section, I can get the data, which I then appended in StringBuilder, and got error when i tried var bytes = Convert.FromBase64String(stringBuilder.ToString()); says invalid character in Base64 string. – ony19161 Oct 30 '20 at 12:29
  • The output from exiftool would not be in Base64, but the actual jpeg file (binary data). Is `exeProcess.OutputDataReceived` converting to Base64 for you, required the need to convert it back? Otherwise, I can't help beyond this because I don't know C#, just exiftool. – StarGeek Oct 30 '20 at 15:55