2010-11-22 4 views
4

나는 C#으로 작성된 프로그램과 praat (음성학 소프트웨어)로 계산 된 값을 가지고 있습니다. 이미 Windows 콘솔 (cmd.exe)에 결과를 인쇄하는 praatcon.exe로 실행중인 praat 스크립트가 있습니다. C# 응용 프로그램에서이 결과를 사용할 수 있습니까? 방법?C# 프로그램을 사용하여 praat에서 값 얻기

또는 결과를 얻는 더 좋은 방법이 있습니다. 예 : 명령 "sendsocket"이 있습니까? 이걸 어떻게 사용합니까?

편집 : praatcon.exe으로 "-a"매개 변수를 사용하는 것이 매우 중요합니다

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

:이 코드가 잘 작동. 설명 here을 참조하십시오.

답변

5

다음은 다른 exe의 콘솔 출력을 캡처하는 방법입니다.

이것은 모두 System.Diagnostics 네임 스페이스에 있습니다.

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

Windows Forms 응용 프로그램에서이 코드를 사용했는데 잠시 동안 콘솔을 열고 올바른 해결책을 보여줍니다. 하지만 내 문자열은 비어 있습니다. p.StandardOutput.ReadToEnd()가 제대로 작동하지 않는 것 같습니다. 어쩌면 다른 스레드의 표준 출력을 읽을 수 있습니까? 내가 도대체 ​​뭘 잘못하고있는 겁니까? –

+0

좋습니다, 코드가 잘 작동합니다! "나의"실수는 praatcon.exe에 "-a"인수를 부르지 않았다는 것입니다! –

0

필요한 데이터를 얻기 위해 praat에 연결하는 서비스가 있어야한다고 생각합니다.