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. The syntax is the same as that of the writeInfo command.

Most system commands are different on different platforms. For instance, to throw away all WAV files in the directory whose name (relative to the script's directory) is in the variable directory$, you would write

runSystem: "del ", directory$, "\*.wav"

on Windows, but

runSystem: "rm ", directory$, "/*.wav"

on Macintosh and Linux.

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

runSystem: "rm ", directory$, "/*.wav"

will stop the script if there are no WAV files in the directory. In order to prevent this, you can tell Praat to ignore the return value of the runSystem command.

Thus, to make sure that the directory contains no WAV files, you would write

runSystem_nocheck: "rm ", directory$, "/*.wav"

Getting the values of system variables

environment$ (symbol-string)
returns the value of an environment variable, e.g.
    homeDirectory$ = environment$ ("HOME")

Getting system duration

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:

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

Links to this page

© ppgb, October 12, 2014