How to use system(), where is it documented?

In the documentation under Saving Sound Files there is a code example using a function called system:

; delete the file (do this with care!)
; only works under Unix (not Windows)
exec system("rm ./a-snd-file.snd")

It seems like this function is capable of running command line commands. Unfortunately I couldn’t get it to work though.

For example:

exec system("touch /home/fedora/test.txt")

If ran on Linux, this should create a new empty text file. But it seems to do nothing and I get no errors.

I also can’t seem to get any output from it. For example:

return string(system("echo foo"))

This code returns “T”, while I would have expected it to return “foo”. I don’t know what to make out of this.

Is the system() function documented somewhere?

There’s a few commands that are only available in stand-alone Nyquist. These include SYSTEM, EXIT, PEEK, POKE, and probably a few others. I think they’ve been omitted because they would make it too easy for bad actors to create malicious plug-ins for Audacity. (The EXIT command was removed most recently, because it is inherently unsafe to quit Nyquist while it is running inside Audacity).

I see, that makes sense. I was hoping to use system to create directories. Do you know if there is another way to create a directory using Nyquist?

There’s been a couple of cases where I’d have liked to use SYSTEM, but I agreed with the other developers that it was too risky for inclusion in Audacity.
I don’t think it’s possible for Nyquist in Audacity to create (or delete) directories, or to delete files.

Depending on what you are doing, you may be able to make use of the FILE widget to select an existing file / directory (

I see… very unfortunate. :confused:
But thanks for the info anyway. :slight_smile:

If you want to create a file, you can do that with OPEN.
Example, creating an empty text file:

(setf myfile "/fully/qualified/path/to/file")
(setf fp (open myfile :direction :output))
;; To print to the file, use (format fp "Text to print")
(close fp)