02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5<br />

Shell<br />

For example, you might be tempted to specify redirection streams when spawning<br />

a routine as a task, intending to send the output of printf( )calls in the new task to<br />

an output stream, while leaving the shell’s I/O directed at the virtual console. This<br />

stratagem does not work. For example, the shell input line:<br />

-> taskSpawn (...myFunc...) > output<br />

momentarily redirects the shell standard output during the brief execution of the<br />

spawn routine, but does not affect the I/O of the resulting task. To redirect the<br />

input or output streams of a particular task, call ioTaskStdSet( ) once the task<br />

exists.<br />

5<br />

Scripts: Redirecting Shell I/O<br />

A special case of I/O redirection concerns the I/O of the shell itself; that is,<br />

redirection of the streams the shell’s input is read from, and its output is written to.<br />

The syntax for this is simply the usual redirection specification, on a line that<br />

contains no other expressions.<br />

The typical use of this mechanism is to have the shell read and execute lines from<br />

a file. For example, the input lines:<br />

➊<br />

➋<br />

-> < /usr/fred/startup<br />

cause the shell to read and execute the commands in the file startup, either on the<br />

current working directory as in ➊ or explicitly on the complete path name in ➋.If<br />

your working directory is /usr/fred, commands ➊ and ➋ are equivalent.<br />

Such command files are called scripts. Scripts are processed exactly like input from<br />

an interactive terminal. After reaching the end of the script file, the shell returns to<br />

processing I/O from the original streams.<br />

During execution of a script, the shell displays each command as well as any<br />

output from that command. You can change this by invoking the shell with the -q<br />

option; see the windsh reference entry (online or in D. <strong>Tornado</strong> Tools Reference).<br />

An easy way to create a shell script is from a list of commands you have just<br />

executed in the shell. The history command h( ) prints a list of the last 20 shell<br />

commands. The following creates a file /tmp/script with the current shell history:<br />

-> h > /tmp/script<br />

The command numbers must be deleted from this file before using it a shell script.<br />

189

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!