dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] t/spawn: maybe check popen_rd w/ 2>&1 redirect
Date: Wed, 27 Sep 2023 05:38:59 +0000	[thread overview]
Message-ID: <20230927053859.683866-1-e@80x24.org> (raw)

I didn't end up relying on this feature, but redirecting stderr
to stdout for `popen_rd' should work on the pipe.
---
 t/spawn.t | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/t/spawn.t b/t/spawn.t
index 9ed3be36..1fc6284d 100644
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -103,6 +103,19 @@ EOF
 	ok(!$l, 'tied readline works for EOF');
 }
 
+if (0) { # we don't actually rely on this, yet, but maybe we will some day:
+	my $fh = popen_rd([qw(sh -c), 'echo >&2 err'], undef, { 2 => 1 });
+	is(my $l = <$fh>, "err\n", '2>&1 redirect');
+	is($l = <$fh>, undef, 'EOF after 2>&1');
+	ok(close($fh), 'close 2>&1');
+	$fh = popen_rd([qw(sh -c), 'echo out; echo >&2 err'], undef,
+			{ 2 => 1 });
+	my @l = <$fh>;
+	@l = sort(@l);
+	is_deeply(\@l, [ "err\n", "out\n" ], 'both out and err captured');
+	ok(close($fh), 'close 2>&1');
+}
+
 {
 	my $fh = popen_rd([qw(printf foo\nbar)]);
 	ok(fileno($fh) >= 0, 'tied fileno works');

                 reply	other threads:[~2023-09-27  5:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230927053859.683866-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).