Previous: , Up: Start & Stop   [Contents][Index]

2.2 Batch Mode

You can have LUX run in batch mode: in the background, unconnected to a terminal, even after you have logged out. To make this work, you need to be able to do three things:

  1. Make LUX take all input from a disk file rather than from the keyboard.
  2. Make LUX send all output to a disk file or discard it rather than send it to the screen.
  3. Put LUX in the background where it can run unconnected to any terminal.

The first item can be taken care of by LUX itself; the last two items must be done by the shell in which you start LUX. Of course, you cannot use any commands that generate screen output or that rely on screen or mouse input if the LUX process is unconnected to a terminal.

To make LUX read commands from a file, use file inclusion (File Inclusion): The command


makes LUX read commands from file file.lux. However, if the file contains a command that requests user input, then such input is read from the keyboard by default. You can instruct LUX to read such input from the file, too, by issuing the batch command (batch).

The following discussion of input and output redirection and of background processes is valid for most Unix-type operating systems.

In most Unix-type shells, you make a command send all output to a disk file by appending a file name after a greater-than (>) sign to the command line, and make the command take input from a disk file by appending a file name after a less-than (<) sign, and make the command run in the background, unconnected to any terminal, by ending the command line with an ampersand (&) sign.

The command

lux batch statements exit > outputfile &

executes the listed statements in LUX, takes all input (if any) from the read files, sends all output to file outputfile, and runs in the background. In this case, you must explicitly tell LUX to exit (using the exit command, exit) when it is done, or else it will hang around in the background waiting for more input. If no additional user input is required during execution of the statements, then you can leave out the batch command. In most cases, the shell will complain if file outputfile already exists. If you use double greater-than signs (>>) rather than a single one, then the output is appended to outputfile, which may or may not already exist. In some shells, if you use a greater-than sign followed by an exclamation mark (>!), then if outputfile already exists its previous contents are discarded.

If all of your LUX commands are in a single file inputfile, then you can also use the following command to execute these commands in the background:

lux < inputfile > outputfile &

If LUX finds that it cannot get more input because it has read all of the input file and it is not connected to a terminal (as in this case), then it quits, so you do not need to have an exit command at the end of inputfile in this case.

If you are running LUX connected to a terminal and then decide you’d rather have it continue in the background, then you can send it the "suspend" interrupt signal, commonly generated by pressing C-Z, and then type the shell command bg to put the session in the background. However, you cannot have subsequent output be sent to a file in this way, so if LUX generates any output after it is put in the background in this way, then the process will hang around until it gets reattached to a terminal. Likewise, if LUX is ready for more input, the process will wait around for that. To reattach the process to the terminal, type fg.

Previous: , Up: Start & Stop   [Contents][Index]