My bosswrap.pl
将生成元素中包含空格的任意数组。它通过系统调用重复发送数组wrapped.pl
,它根据数组创建 STDOUT。
随后,bosswrap.pl
必须附加 STDOUTwrapped.pl
到一个文件bosswrap.pl
控制。这就是我被困住的地方。第一的wrapped.pl
:
#!/usr/bin/perl
use strict; use warnings;
print "inside $0\n";
my $countarrayelements=0;
for my $item ( @ARGV ) {
$countarrayelements++;
print "$countarrayelements: |$item|\n";
}
Then bosswrap.pl
:
#!/usr/bin/perl
use strict; use warnings;
my $fileresult = "trash.txt";
unlink $fileresult; # rm any existing file
my $handlefileresult;
my @array = ( 5, "don't you . . . ", "\x09\x21", "\x3f \x21" );
my $count=0;
print "inside $0\n";
for my $element ( @array ) {
$count++;
print "$count\t|$element|\n";
}
#https://stackoverflow.com/questions/50553031/calling-a-shell-command-with-multiple-arguments
#list form: command line arguments pass verbatim, avoid shell interpolation
system("wrapped.pl", @array) == 0 or die "system failed: \$? = $?";
#This block sends the return code, not the STDOUT, to handlefileresult
open( $handlefileresult, ">> ", $fileresult) || die "$0: can't open $fileresult for appending$!";
print $handlefileresult "not a system call\n";
print {$handlefileresult} system("wrapped.pl", @array) == 0 or die "system failed: \$? = $?";
close ( $handlefileresult ) || die;
#In the following block, select unfortunately will not redirect output of system call:
open( $handlefileresult, ">> ", $fileresult) || die "$0: can't open $fileresult for appending$!";
select $handlefileresult;
print "selected; BEFORE system call\n";
system("wrapped.pl", @array) == 0 or die "system failed: \$? = $?";
print "selected; AFTER system call\n";
close ( $handlefileresult ) || die;
再次,我想反复打电话wrapped.pl
从内部bosswrap.pl
并将这些系统调用的输出放入$fileresult
.
建议回复 @ikegamiuse IPC::Run qw( run );
但这会引发错误。我在 Macos 上运行 Perl。必须做什么才能使其发挥作用?
> perl --version
This is perl 5, version 18, subversion 4 (v5.18.4) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2013, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
> bosswrap.pl
Can't locate IPC/Run.pm in @INC (you may need to install the IPC::Run module) (@INC contains: /sw/lib/perl5/darwin-thread-multi-2level /sw/lib/perl5 /sw/lib/perl5/darwin /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.4 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /Users/BNW/u/kh/bin/bosswrap.pl line 3.
BEGIN failed--compilation aborted at /Users/BNW/u/kh/bin/bosswrap.pl line 3.
>
基于安装缺少的 Perl 模块的最简单方法是什么? https://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module I did
> cpan IPC::Run
<snip>
Appending installation info to /Users/BNW/perl5/lib/perl5/darwin-thread-multi-2level/perllocal.pod
TODDR/IPC-Run-20180523.0.tar.gz
/usr/bin/make install -- OK
然后重新启动这台MacBook Pro 10.14.6。但我显然得到了同样的错误:
> bosswrap.pl
Can't locate IPC/Run.pm in @INC (you may need to install the IPC::Run module) (@INC contains: /sw/lib/perl5/darwin-thread-multi-2level /sw/lib/perl5 /sw/lib/perl5/darwin /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.4 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /Users/BNW/u/kh/bin/bosswrap.pl line 3.
BEGIN failed--compilation aborted at /Users/BNW/u/kh/bin/bosswrap.pl line 3.
>
我怎样才能解决这个问题?