system
Prev | Orchestra Opcodes and Operators | Next

## system

system — Call an external program via the system call

## Description

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

## Syntax

    ires system_i itrig, Scmd, [inowait]

    kres system ktrig, Scmd, [knowait]

## Initialization

Scmd -- command string

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

## Performance

ktrig -- if greater than zero and different from the value on the previous control cycle the opcode performs the requested printing. 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.

## Example

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

Example 845. Example of the system opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in
    -odac          ; -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o system.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 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>

    ; Play Instrument #1 for thirty seconds.
    i 1 0 1
    i 2 5 1
    e

    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: John ffitch
2007

New in version 5.06

Prev | Up | Next
syncphasor | Home | tb