3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
# Helper tool to read or write data to/from stdin/stdout
12
# IpcCat {write|read|dump|getenv} arg
15
# write: read from stdin and write to file <arg>
16
# read: read from file <arg> and write to stdout
17
# dump: read from stdin; write to stdout
18
# getenv: print value of environment variable <arg>
28
open IN, $fn or die $!;
43
#$| = 1; # disable buffering of output
45
# wait a little before doing anything
46
select(undef, undef, undef, 0.1);
48
if ($ARGV[0] =~ /^dump$/i) {
49
print STDERR "Starting dump\n";
51
my $buf = readFile("-");
53
print STDERR sprintf("Dumped %d bytes\n", length($buf));
55
elsif ($ARGV[0] =~ /^read$/i) {
56
print STDERR "Starting read\n";
58
my $buf = readFile($ARGV[1]);
61
print STDERR sprintf("Read %d bytes\n", length($buf));
63
elsif ($ARGV[0] =~ /^write$/i) {
65
open(OF, ">$of") or die $!;
66
print STDERR "Starting write\n";
68
my $buf = readFile("-");
73
print STDERR sprintf("Wrote %d bytes\n", length($buf));
75
elsif ($ARGV[0] =~ /^getenv$/i) {
76
print STDERR sprintf("Reading environment variable %s\n", $ARGV[1]);
77
print STDOUT $ENV{$ARGV[1]};
80
print STDERR "Invalid arguments\n";