-1

In a Windows application I need to run another one application that's tetpdflib. That tetpdflib runs in command prompt only. When I drag and drop exe to the command prompt it will execute. Here is my code:

Process tetmlProcess = new Process();
tetmlProcess.StartInfo.CreateNoWindow = true;
tetmlProcess.StartInfo.UseShellExecute = false;
tetmlProcess.StartInfo.RedirectStandardError = true;
tetmlProcess.StartInfo.RedirectStandardInput = true;
tetmlProcess.StartInfo.WorkingDirectory = @"C:\Users\sw_chn\Documents\PDFlib\TET 5.0 32-bit\bin";
tetmlProcess.StartInfo.FileName = @"C:\Users\sw_chn\Documents\PDFlib\TET 5.0 32-bit\bin\tet.exe";
string args1 = @"tet -m wordplus D:\DailyWork\March\JOURNAL-ISSUE_6_3924-3930.pdf";
tetmlProcess.StartInfo.Arguments = args1;
tetmlProcess.Start();
StreamReader news = tetmlProcess.StandardError;
string err = news.ReadToEnd();
Console.WriteLine(err);
Console.ReadLine();

I had following error:

could not open PDF file 'tet' for reading

How to recover from this?

sinsedrix
  • 3,341
  • 3
  • 20
  • 38
Malathi Mals
  • 73
  • 10
  • 2
    Do you really need "tet" as first argument? (so `tet.exe tet -m wordplus ...`) – Hans Kesting Mar 08 '17 at 09:08
  • 2
    Remove `"tet"` from your `args1` string – Smartis Mar 08 '17 at 09:08
  • Thats the command why need to remove. – Malathi Mals Mar 08 '17 at 09:09
  • @MalathiMals, no, the command is in `Process.StartInfo.FileName`. The Arguments is what you write *after* you wrote the file name (That is: `-m wordplus D:\DailyWork\March\JOURNAL-ISSUE_6_3924-3930.pdf` ) – Ori Nachum Mar 08 '17 at 09:13
  • sting str = D:\DailyWork\March\JOURNAL-ISSUE_6_3924-3930.pdf string args1 = @"-m wordplus" + " " + str; tetmlProcess.StartInfo.Arguments = args1; what is the error on that? again i got same error as pdf could not open – Malathi Mals Mar 08 '17 at 09:18

1 Answers1

1

Your Start Arguments contains the Program Name again which leads to this error.

Simply change your code

Process tetmlProcess = new Process();
// ...
tetmlProcess.StartInfo.WorkingDirectory = @"C:\Users\sw_chn\Documents\PDFlib\TET 5.0 32-bit\bin";
tetmlProcess.StartInfo.FileName = @"C:\Users\sw_chn\Documents\PDFlib\TET 5.0 32-bit\bin\tet.exe";
// removing "tet" in Arguments
string args1 = @"-m wordplus D:\DailyWork\March\JOURNAL-ISSUE_6_3924-3930.pdf";
tetmlProcess.StartInfo.Arguments = args1;
tetmlProcess.Start();
// ...

Conclusion

The manual contains example like this

tet --format utf16 --outfile file.utf16 file.pdf

Here is tet mapped as environment variable in the system and stands for the full path of the application.

Smartis
  • 4,669
  • 3
  • 29
  • 44
  • sting str = D:\DailyWork\March\JOURNAL-ISSUE_6_3924-3930.pdf string args1 = @"-m wordplus" + " " + str; tetmlProcess.StartInfo.Arguments = args1; what is the error on that? again i got same error as pdf could not open – Malathi Mals Mar 08 '17 at 09:31