From 07f639c9219968a01d5c722424e9c61d3b146014 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 25 Oct 2023 00:29:25 +0000 Subject: spawn: support synchronous run_qx This is similar to `backtick` but supports all our existing spawn functionality (chdir, env, rlimit, redirects, etc.). It also supports SCALAR ref redirects like run_script in our test suite for std{in,out,err}. We can probably use :utf8 by default for these redirects, even. --- t/spawn.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/spawn.t b/t/spawn.t index 1af66bda..4b3baae4 100644 --- a/t/spawn.t +++ b/t/spawn.t @@ -3,7 +3,7 @@ # License: AGPL-3.0+ use v5.12; use Test::More; -use PublicInbox::Spawn qw(which spawn popen_rd); +use PublicInbox::Spawn qw(which spawn popen_rd run_qx); require PublicInbox::Sigfd; require PublicInbox::DS; @@ -19,6 +19,17 @@ require PublicInbox::DS; is($?, 0, 'true exited successfully'); } +{ + my $opt = { 0 => \'in', 2 => \(my $e) }; + my $out = run_qx(['sh', '-c', 'echo e >&2; cat'], undef, $opt); + is($e, "e\n", 'captured stderr'); + is($out, 'in', 'stdin read and stdout captured'); + $opt->{0} = \"IN\n3\nLINES"; + my @out = run_qx(['sh', '-c', 'echo E >&2; cat'], undef, $opt); + is($e, "e\nE\n", 'captured stderr appended to string'); + is_deeply(\@out, [ "IN\n", "3\n", 'LINES' ], 'stdout array'); +} + SKIP: { my $pid = spawn(['true'], undef, { pgid => 0 }); ok($pid, 'spawned process with new pgid'); -- cgit v1.2.3-24-ge0c7