You may wish to run HP BASIC/UX as a background process to free up your invoking window. This is accomplished by typing an ampersand (&) after the rmb command and options. For example, if you execute:
rmb -w3M -fg yellow &
from an hpterm window in X11, rmb will start up with a 3 MB workspace size and a foreground color of yellow, and the hpterm window will be free for other HP-UX commands (you will see a shell prompt).
Running rmb as a background process has some side effects that you should be aware of. The BASIC/UX window will be created the same as if BASIC/UX were running in the foreground. Input and output will also behave similarly. The only difference is that the window from which you started rmb will return with a shell prompt so that you can continue with other HP-UX commands.
If you are running rmb as a background process or have redirected standard input and attempt to execute a shell or a command that requires input, the shell used to control the EXECUTE command will inherit its input from the rmb standard input stream.
Similarly, if you perform an EXECUTE command that produces output, the output will be sent to the rmb standard output stream. For example:
EXECUTE "ls"
normally produces a listing of all the files in the current directory and sends it to your terminal window. However, if you have redirected standard output for the rmb process, then the output from the EXECUTE command will be sent to the same place as the rmb standard output. You can specify that the standard output of the EXECUTE command be sent somewhere other than the rmb standard output stream by redirecting the EXECUTE command's output itself. For example,
EXECUTE "ls > rmb.ls"
would save the output of the ls command in rmb.ls.
As mentioned above, standard input is interpreted as commands you type into the BASIC/UX KBD line. This allows you to automate procedures that you have to repeat many times by writing BASIC scripts. For example, a script to convert a PROG or PROG2 file into ASCII format would look like this:
LOAD "PROG_FILE"
SAVE "ASCII_FILE"
This example can be expanded to convert all the files in a BASIC/UX application so that they can be used under source code control.
If only standard input is redirected and not standard output, the BASIC/UX display will come up as usual, but the keyboard will be dead. This scenario may be useful for demonstrations. However, you should be aware that if your demonstration programs contain statements that expect a live keyboard (e.g., ON KBD and ON KEY), you may need to recode your program so that it is not dependent on those statements. When the end of the input stream is reached, BASIC/UX will exit. When standard input is redirected, BASIC/UX defaults to CAPS LOCK mode disabled. This allows literal strings to be interpreted correctly by BASIC/UX. For example, suppose the following line was part of the redirected input:
20 SYSTEM$("MSI")
If CAPS LOCK mode were enabled, BASIC/UX would interpret this as:
20 system$("msi")
The system$ would be recognized as a BASIC/UX keyword (BASIC/UX automatically converts keywords to upper case), but the msi literal would cause an error.
The standard input stream can contain the 2-byte non-ASCII character sequences as listed in the HP BASIC Interface Reference. You can send non-ASCII character sequences to BASIC/UX by using the escape character in the vi editor (i.e., [CTRL]-[V] [Esc]) which will appear as: ^[. For example,
^[H^[>^[>^[>^[>^[>
will position the cursor at the beginning of the line (^[H) and then move it five spaces to the right (^[>^[>^[>^[>^[>). Also, if you have a program with literal strings containing the non-ASCII keycode sequences which was SAVEd by BASIC/UX , the keycode sequences will be interpreted correctly. These keycode sequences can be identified with an inverse-video K (character code 255) followed by an ASCII character.
Redirecting standard input disables the live keyboard. The input stream is read serially. Thus, ON KBD, ON KEY, and similar events can never occur.
If you have existing programs which depend on the asynchronous nature of these statements, they will need to be changed. However, this allows the standard input stream to contain data for INPUT, LINPUT, and ENTER KBD statements. Standard input is not read while rmb is in the Running state, but as soon as an Input? state occurs, rmb will read from the input stream. Note that as soon as a program pauses, rmb starts reading from standard input.
Thus, if there is a PAUSE somewhere before an INPUT statement in the program, data will be lost. If you know that there is a PAUSE in the program, you can cause the program to continue by including the 2-byte key sequence for the {{Continue}} softkey (^[C) as part of your input file.
If there is a syntax error in the input stream, a BASIC error message is generated. If the KBD buffer has not been cleared (as is the case with syntax errors), the next line of input that rmb reads will also cause an error. Thus, it is possible for one error in the BASIC script to cause a cascade of errors. Turning on PRINTALL mode (CONTROL KBD,1;1) at the beginning of your BASIC script will aid in debugging any problems you may encounter when redirecting input.
If standard output is redirected, no graphics is permitted to the display (graphics to HPGL devices is still allowed). No windows are created and all window commands generate an error. The only output from rmb that appears in the standard output is output which would have appeared in the Output Area of the display. One exception to this is that the EDIT screen is not output. This does not mean that you cannot edit a program (via OUTPUT KBD or the non-ASCII character sequences mentioned above), only that the EDIT screen will not appear in the standard output.
If you run rmb in the foreground and redirect standard output but not standard input, the live keyboard will be active. However, since output is redirected, the soft keys will not appear and PRINT or OUTPUT,CRT output will be sent to standard out. If you have not redirected standard error, DISP, INPUT, and LINPUT strings and BASIC errors will appear on your terminal device.
If you run rmb in the background and redirect standard output but not standard input, the keyboard will not be active. The rmb process will attempt to get input from the null file and exit.
Any output from the rmb process which would have appeared in the Display Line or Message Results Line will be sent to the standard error file. If you turn on PRINTALL mode in your BASIC script, output to the Display Line and Message Results Line will also appear in the standard output file. The following is an example of redirecting standard input, standard output, and standard error:
rmb < rmb.input > rmb.output 2> rmb.error &
A new STATUS register has been defined so that you can determine the foreground/background and redirected I/O status of the rmb process. This information can help you decide programmatically whether or not to perform certain functions, such as an EXECUTE.
STATUS Register 5
Background and standard I/O status
Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
---|---|---|---|---|---|---|---|
0 |
0 |
0 |
0 |
Back- ground Process | stderr Redirected | stdout Redirected | stdin Redirected |
Value=128 | Value=64 | Value=32 | Value=16 | Value=8 | Value=4 | Value=2 | Value=1 |
Operation | Behavior
|
---|---|
rmb | Operates as originally defined. |
rmb MYPROG | Operates as originally defined. |
rmb < MYKBD
|
Starts rmb.
No active keyboard. Uses MYKBD as keyboard input, then EXITs. Retains possession of EXECUTE window. |
rmb MYPROG < MYKBD
|
Starts rmb.
No active keyboard. Runs MYPROG. Uses MYKBD as keyboard input, then EXITs. Retains possession of EXECUTE window. |
rmb > OUTFILE
|
Starts rmb.
No visible display. No graphics. No window commands. Live keyboard active. Printed output goes to OUTFILE. EXITs with QUIT. |
rmb MYPROG
> OUTFILE
|
Starts rmb.
No visible display. No graphics. No window commands. Runs MYPROG. Live keyboard active. Printed output goes to OUTFILE. EXITs with QUIT. |
rmb < MYKBD
> OUTFILE
|
Starts rmb.
No visible display. No graphics. No active keyboard. Uses MYKBD as keyboard input. Printed output goes to file OUTFILE. EXITs on end of MYKBD. |
rmb MYPROG
< MYKBD > OUTFILE
|
Starts rmb.
No visible display. No graphics. No window commands. No active keyboard. Runs MYPROG. Uses MYKBD as keyboard input. Printed output goes to file OUTFILE. EXITs on end of MYKBD. |
rmb &
|
Creates full-function BASIC/UX window and operates normally. |
rmb MYPROG &
|
Creates full-function BASIC/UX window.
Runs MYPROG, then operates normally. |
rmb < MYKBD &
|
Creates full-function BASIC/UX window.
Uses MYKBD as keyboard input, then EXITs. |
rmb MYPROG
< MYKBD &
|
Creates full-function BASIC/UX window.
Runs MYPROG. Uses MYKBD as keyboard input, then EXITs. |
rmb > OUTFILE & | EXITs. |
rmb MYPROG
> OUTFILE &
|
Starts rmb.
No visible display. No graphics. No active keyboard. Runs MYPROG. Printed output goes to file OUTFILE, then EXITs. |
rmb < MYKBD
> OUTFILE &
|
Starts rmb.
No visible display. No graphics. No active keyboard. Uses MYKBD as keyboard input. Printed output goes to file OUTFILE. EXITs on end of MYKBD. |
rmb MYPROG
< MYKBD > OUTFILE &
|
Starts rmb.
No visible display. No graphics. No active keyboard. Runs MYPROG. Uses MYKBD as keyboard input. Printed output goes to file OUTFILE. EXITs on end of MYKBD. |