Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

5.4 Run an operating-system command

Use the IOC shell’s system command to run a Linux shell command. An IOC command and an operating-system command use different entry points.

  1. In the generated application root, find the DBD inclusion:

    grep 'system.dbd' jeonglee_DemoApp/src/Makefile
    

    Common_DBDs += system.dbd includes the registrar for system in the application DBD. Support registration makes it available to the IOC.

  2. In an activated Bash terminal, start a soft IOC in a scratch directory:

    SYSTEM_WORK="$(mktemp -d)"
    cd "$SYSTEM_WORK"
    softIoc
    
  3. At the IOC prompt, compare these commands:

    pwd
    system pwd
    system(pwd)
    system("pwd")
    

    Each prints the working directory. pwd is an IOC shell command; the other forms invoke the operating system’s pwd through system.

  4. Pass commands containing spaces as one quoted argument:

    system("mkdir test_folder")
    system("test -d test_folder && printf 'directory exists\n'")
    

    The second command prints directory exists. An unquoted system mkdir test_folder supplies two arguments to a command that expects one; it does not express the intended shell command.

  5. Stop the soft IOC:

    exit
    

    In the returned Bash shell, inspect the result:

    ls -ld test_folder
    

    The directory exists under SYSTEM_WORK. system uses the IOC process’s account, environment, and current directory.

  6. Leave and remove the scratch directory:

    cd ~
    rm -rf "$SYSTEM_WORK"