Scripting 6.5. Calling system commands

From a Praat script you can call system commands. These are the same commands that you would normally type into a terminal window or into the Window command line prompt.

system command
executes a system command.

Some system commands are identical on all platforms (Macintosh, Windows, Unix):

system mkdir sounds

which creates a new directory sounds in the directory of the script. Some other system commands are different on different platforms. For instance, to throw away all WAV files in the script's directory, you would write

system del *.wav

on Windows, but

system rm *.wav

on Macintosh and Unix.

The script will stop running if a system command returns an error. For instance,

system mkdir sounds

will stop the script if the directory sounds already exists. In order to prevent this, you can tell Praat to ignore the return value of the system command:

system_nocheck command
executes a system command, ignoring any errors.

Thus, to make sure that the directory sounds exists, you would write

system_nocheck mkdir sounds
environment$ (symbol-string)
returns the value of an environment variable, e.g.
    homeDirectory$ = environment$ ("HOME")
stopwatch
returns the time that has elapsed since the previous stopwatch.

Here is a Praat script that measures how long it takes to do a million assignments:

stopwatch
for i to 1000000
    a = 1.23456789e123
endfor
time = stopwatch
writeInfoLine (a, " ", fixed (time, 3))

Links to this page


© ppgb, April 7, 2013