xref: /linux/tools/testing/selftests/kselftest/prefix.pl (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1#!/usr/bin/env perl
2# SPDX-License-Identifier: GPL-2.0
3# Prefix all lines with "# ", unbuffered. Command being piped in may need
4# to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
5use strict;
6use IO::Handle;
7
8binmode STDIN;
9binmode STDOUT;
10
11STDOUT->autoflush(1);
12
13my $needed = 1;
14while (1) {
15	my $char;
16	my $bytes = sysread(STDIN, $char, 1);
17	exit 0 if ($bytes == 0);
18	if ($needed) {
19		print "# ";
20		$needed = 0;
21	}
22	print $char;
23	$needed = 1 if ($char eq "\n");
24}
25