Expecting A Null Character

The null character is another name for a zero-valued byte.[30] Tcl provides no way to represent nulls in strings. Indeed, internally Tcl reserves null to delimit strings—so even if you could get a null in a string, you cannot do anything useful with the result. Fortunately, this is not a problem.

Nulls are almost never generated by interactive processes. Since they have no printing representation, users cannot see them and so there is little point in sending nulls to users. Nonetheless, nulls have valid uses. The most common use for nulls is to control screen graphics. The nulls are used either to delay character arrival on slow screens or as parameters to screen formatting operations. Both of these operations work correctly in Expect. Expect passes nulls to the standard output just like any other character.

By default, Expect removes any nulls before doing pattern matching. This is done for efficiency—it allows the pattern matcher to use the same internal representation of strings that Tcl uses.

Removal of nulls can be disabled with the remove_nulls command. The nulls can then be matched explicitly using the null keyword. To prevent nulls being removed from the output of the currently spawned process, use the command remove_nulls with an argument of 0. The following fragment calls remove_nulls and then looks for a null in the output.

remove_nulls 0
expect null

An argument of 1 causes nulls to be removed. The remove_nulls command handles its arguments similarly ...

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.