Skip to content

system

Call an external program via the system call.

📝 Note

Up to Csound 6, systemi was called system_i.

Plugin opcode in system_call.

system and systemi call any external command understood by the operating system, similarly to the C function system(). systemi runs at i-time only, while system runs both at initialization and performance time.

Syntax

ires = systemi(itrig, Scmd, [inowait])
kres = system(ktrig, Scmd, [knowait])
ires system_i itrig, Scmd, [inowait]
kres system ktrig, Scmd, [knowait]

Initialization

Scmd -- command string

itrig -- if greater than zero the opcode executes the command; otherwise it is an null operation.

Performance

ktrig -- if greater than zero and different from the value on the previous control cycle the opcode executes the command. Initially this previous value is taken as zero.

inowait, knowait -- if given an non zero the command is run in the background and the command does not wait for the result. (default = 0)

ires, kres -- the return code of the command in wait mode and if the command is run.In other cases returns zero.

More than one system command (a script) can be executed with a single system opcode by using double braces strings {{ }}.

📝 Note

This opcode is very system dependant, so should be used with extreme care (or not used) if platform neutrality is desired.

Examples

Here is an example of the systemi opcode. It uses the file system-modern.csd.

Example of the systemi opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in
-n   ; no sound
; For Non-realtime ouput leave only the line below:
; -o system.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments> 

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1
  ; Waits for command to execute before continuing
  res:i = systemi(1, {{      ps
            date
            cd ~/Desktop
            pwd
            ls -l
            whois csounds.com
          }})
  print(res)
  turnoff()
endin

instr 2
  ; Runs command in a separate thread
  res:i = systemi(1, {{      ps
            date
            cd ~/Desktop
            pwd
            ls -l
            whois csounds.com
          }}, 1)
  print(res)
  turnoff()
endin

</CsInstruments>
<CsScore>
i 1 0 1
i 2 5 1
e
</CsScore>
</CsoundSynthesizer> 

Here is an example of the system_i opcode. It uses the file system.csd.

Example of the system_i opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in
-n   ; no sound
; For Non-realtime ouput leave only the line below:
; -o system.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments> 

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1
; Waits for command to execute before continuing
ires system_i 1,{{     ps
            date
            cd ~/Desktop
            pwd
            ls -l
            whois csounds.com
        }}
print ires
turnoff
endin

instr 2
; Runs command in a separate thread
ires system_i 1,{{     ps
            date
            cd ~/Desktop
            pwd
            ls -l
            whois csounds.com
        }}, 1

print ires
turnoff
endin

</CsInstruments>
<CsScore>
i 1 0 1
i 2 5 1
e
</CsScore>
</CsoundSynthesizer> 

See also

Miscellaneous opcodes

Credits

Author: John ffitch
2007

New in version 5.06