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.
-
In the generated application root, find the DBD inclusion:
grep 'system.dbd' jeonglee_DemoApp/src/MakefileCommon_DBDs += system.dbdincludes the registrar forsystemin the application DBD. Support registration makes it available to the IOC. -
In an activated Bash terminal, start a soft IOC in a scratch directory:
SYSTEM_WORK="$(mktemp -d)" cd "$SYSTEM_WORK" softIoc -
At the IOC prompt, compare these commands:
pwd system pwd system(pwd) system("pwd")Each prints the working directory.
pwdis an IOC shell command; the other forms invoke the operating system’spwdthroughsystem. -
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 unquotedsystem mkdir test_foldersupplies two arguments to a command that expects one; it does not express the intended shell command. -
Stop the soft IOC:
exitIn the returned Bash shell, inspect the result:
ls -ld test_folderThe directory exists under
SYSTEM_WORK.systemuses the IOC process’s account, environment, and current directory. -
Leave and remove the scratch directory:
cd ~ rm -rf "$SYSTEM_WORK"