Commands that read from the console

1 minute read

When GNU Make or NMAKE invokes a makefile target command, that process inherits the standard I/O streams of the Make process. It is then possible to invoke commands that expect input during a build, either from the terminal or passed into the Make standard input stream. For example, a makefile such as:

all: @cat

could be invoked like this:

% echo hello | gmake hello

More commonly, a command in a makefile might prompt the user for some input, particularly if the command encounters an error or warning condition:

all: @rm -i destroy
% gmakerm: remove regular file `destroy'? y

Neither of these constructs is generally recommended because systems that require runtime user input are tedious to invoke and extremely difficult to automate.

Because CloudBees Build Acceleration runs commands on cluster hosts where processes do not inherit the I/O streams and console of the parent eMake, makefiles (such as the examples above) with commands expecting interactive input are not supported.

In the majority of cases, tools that prompt for console input contain options to disable interactive prompting and proceed automatically. For example, invoking “ rm ” without the “ i ” enables this behavior. For those that do not, explicitly feeding expected input (either from a file or directly by shell redirection or piping) will suffice. For example:

all:echo y | rm -i destroy

Finally, tools such as Expect (see that automate an interactive session can be used for commands that insist on reading from a console.