4

I have a program written in C# and values calculated by praat (phonetics software). I already have a praat script running with praatcon.exe which prints the results on a Windows console (cmd.exe). Can I use this result in my C# application? How?

Or is there a better way to get the results, e.g. with the command "sendsocket"? How to use this one?

Edit: It works great with this code:

ProcessStartInfo si = new ProcessStartInfo();
si.FileName = "praatcon.exe"; //name of the handle program from sysinternals
//assumes that it is in the exe directory or in your path
//environment variable

//the following three lines are required to be able to read the output (StandardOutput)
//and hide the exe window. 
si.RedirectStandardOutput = true;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.UseShellExecute = false;

si.Arguments = "-a example.praat filename.wav"; //you can specify whatever parameters praatcon.exe needs here; -a is mandatory!

//these 4 lines create a process object, start it, then read the output to
//a new string variable "s"
Process p = new Process();
p.StartInfo = si;
p.Start();
string s = p.StandardOutput.ReadToEnd();

It is VERY important to use the "-a" parameter with praatcon.exe. See explanation here.

Dale Athanasias
  • 471
  • 3
  • 16
K B
  • 1,330
  • 1
  • 18
  • 30

2 Answers2

5

Here's how to capture the console output of another exe.

This is all in the System.Diagnostics namespace.

ProcessStartInfo si = new ProcessStartInfo();
si.FileName = "praat.exe";     //name of the program
                                //assumes that its in the exe directory or in your path 
                                //environment variable

//the following three lines are required to be able to read the output (StandardOutput)
//and hide the exe window.
si.RedirectStandardOutput = true;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.UseShellExecute = false;

si.Arguments = "InputArgsHere";     //You can specify whatever parameters praat.exe needs here

//these 4 lines create a process object, start it, then read the output to 
//a new string variable "s"
Process p = new Process();
p.StartInfo = si;
p.Start();
string s = p.StandardOutput.ReadToEnd();
Tim Coker
  • 6,484
  • 2
  • 31
  • 62
  • I tried this code in a Windows Forms application and I can see the console opening and showing the right solution for a short moment. But my string s is empty. Seems as if p.StandardOutput.ReadToEnd() isn't working well. Maybe it reads out the standard output of another thread? What am I doing wrong? – K B Nov 23 '10 at 11:05
  • OK, your code works great! "My" mistake was that I didn't call praatcon.exe with the "-a" argument! – K B Nov 23 '10 at 13:40
0

I think there should be a service which connects you to praat to get required data.

Serkan Hekimoglu
  • 4,234
  • 5
  • 40
  • 64