PHP (PHP 7.3.5)
<?php
$hi = fopen('php://stdin', "r");
$ho = fopen('php://stdout', "w");
while (true) {
fscanf($hi, "%d", $n);
if ($n == 42) break;
fwrite($ho, sprintf("%d\n", $n));
}
fclose($ho);
fclose($hi);
Doubtful Deer