linux passing input the hard way

2 minute read Published: 2020-07-18

For people familiar with Unix philosophy, ["Everything is a file"][everyting_is_file] is a common phrase. Rarely do we get a case to use it in practice. This is one of those cases.

Problem

At work, a pipeline that needed to be run by the end of the day got stuck. After checking the logs, it appeared to be waiting for an input prompt. The prompt was supposed to be bypassed by setting an environment variable, but recent changes had introduced a flaw.

Since the patch would take time and the pipeline was lengthy, we had to manually resume it. However, the prompt wasn't directly available because this process was deeply nested within the pipeline logic.

Solution in Theory

"Everything is a file" in Unix includes directories, devices, and even processes. We can leverage this fact to provide input to a process.

Solution Demonstration

To demonstrate, let us use the cat program.

  1. Run cat in a terminal. It will wait for input.
  2. Use the command echo "Hello World" >> "/proc/$(pidof -s cat)/fd/1" to "Hello World" to the cat program.