Node:Running programs, Next:Job control, Previous:System interface, Up:System interface
To run a program, do: run program args
.
The program (which is quoted) must name an executable file.
The args (which are also quoted) are passed to the program.
Q1> run wc Q.C 308 950 7986 Q.CIf the program is a simple identifier that is not in the scope of a Q variable, and the identifier names an executable file in the current search path, then the
run
may be omitted.
Q2> wc Q.C 308 950 7986 Q.C(Note that determination that program is an executable program is done at compile time, so you cannot omit
run
if
the program hasn't been created yet.)
The standard output from run
is coerced to a string,
which you can use as you use any other string:
Q3> :X = wc Q.C Q4> printf "{%#a}" X {" 308 950 7986 Q.C\n"}
The left-hand argument to a run
command is coerced to a string,
and the result is used as the standard input of the program:
Q5> "Hello World!\n" run /usr/bin/tr a-zA-Z A-Za-z hELLO wORLD!
If an argument contains the "globbing" characters *?[]()|
these are use to match against file names, as in most shells:
Q1> echo Makefi* Makefile Makefile~(
echo
is a builtin command that just prints into arguments.)
The globbing syntax is an extension of that used for most shells;
see Patterns for details.
Tilde expansion is also done.
Q1> "ab cde fgh" run wc 0 3 10
To replace Q by program, do: exec program args
.
By the way, before execution Q translates
run program args
into something very much like:
primitive_run "program" (globlist (quote args))
.
(However, you can't call invoke primitive_run
directly.)