|
A subroutine for sending messages to a running Praat. Also a Unix, MacOS, or DOS console program with the same purpose.
char message [100], *errorMessage;
strcpy (message, "Quit");
errorMessage = sendpraat (NULL, "praat", 0, message);
if (errorMessage != NULL) fprintf (stderr, "%s", errorMessage);
This causes the program Praat to quit (gracefully), because Quit is a fixed command in one of the menus of that program. On Unix and Macintosh, sendpraat returns immediately; on Windows, the timeOut argument is ignored. The return value errorMessage is a statically allocated string internal to sendpraat, and is overwritten by the next call to sendpraat.
Suppose you have a sound file whose name is in the variable fileName, and you want the program Praat, which can play sounds, to play this sound backwards.
char message [1000], *errorMessage;
sprintf (message, "Read from file... %s\nPlay reverse\nRemove", fileName);
errorMessage = sendpraat (NULL, "praat", 1000, message);
This will work because Play reverse is an action command that becomes available in the dynamic menu when a Sound is selected. On Unix, sendpraat will allow Praat at most 1000 seconds to perform this.
Sometimes, it may be unpractical to send a large script directly to sendpraat. Fortunately, the receiving program knows the execute directive:
char message [100], *errorMessage;
strcpy (message, "execute doAll.praat 20");
errorMessage = sendpraat (NULL, "praat", 0, message);
This causes the program Praat to execute the script doAll.praat with an argument of "20".
You can download the source code of the sendpraat subroutine and program via www.praat.org or from http://www.fon.hum.uva.nl/praat/sendpraat.html.
To start a program from the command line instead and sending it a message, you would not use sendpraat, but instead run the program with a script file as an argument. See Scripting 6.9. Calling from the command line.
© ppgb, October 20, 2009