![]() |
![]()
| ![]() |
![]()
NAMEIPC::System::Options - Perl's system(), readpipe()/qx, IPC::Run's run(), start() (with more options) VERSIONThis document describes version 0.341 of IPC::System::Options (from Perl distribution IPC-System-Options), released on 2023-05-24. SYNOPSISuse IPC::System::Options qw(system readpipe run start); # use exactly like system() system(...); # use exactly like readpipe() (a.k.a. qx a.k.a. `` a.k.a. the backtick # operator). if you import readpipe, you'll override the backtick operator with # this module's version (along with your chosen settings). my $res = readpipe(...); $res = `...`; # but these functions accept an optional hash first argument to specify options system({...}, ...); $res = readpipe({...}, ...); # run without shell, even though there is only one argument system({shell=>0}, "ls"); system({shell=>0}, "ls -lR"); # will fail, as there is no 'ls -lR' binary $res = readpipe({shell=>0}, "ls -lR"); # ditto # force shell, even though there are multiple arguments (arguments will be # quoted and joined together for you, including proper quoting on Win32). system({shell=>1}, "perl", "-e", "print 123"); # will print 123 $res = readpipe({shell=>1}, "perl", "-e", "print 123"); # note that to prevent the quoting mechanism from quoting some special # characters (like ">") you can use scalar references, e.g.: system({shell=>1}, "ls", "-laR", ">", "/root/ls-laR"); # fails, because the arguments are quoted so the command becomes: ls '-laR' '>' '/root/ls-laR' system({shell=>1}, "ls", "-laR", \">", "/root/ls-laR"); # works # set LC_ALL/LANGUAGE/LANG environment variable $res = readpipe({lang=>"de_DE.UTF-8"}, "df"); # log using Log::ger, die on failure system({log=>1, die=>1}, "blah", ...); # chdir first before running program (and chdir back afterwards) system({chdir => "/tmp", die => 1}, "some-program"); Set default options for all calls (prefix each option with dash): use IPC::System::Options 'system', 'readpipe', -log=>1, -die=>1; run() is like system() but uses IPC::Run's run() instead of system(): run('ls'); # also accepts an optional hash first argument. some additional options that # run() accepts: stdin. run({capture_stdout => \$stdout, capture_stderr => \$stderr}, 'ls', '-l'); start() is like run() but uses IPC::Run's start() instead of run() to run program in the background. The result is a handle (see IPC::Run for more details) which you can then call finish(), etc on. my $h = start('ls', '-l'); ... $h->finish; DESCRIPTIONThis module provides replacement (wrapper) for Perl's system(), readpipe() (qx//, a.k.a. the backtick operator), as well as IPC::Run's start() and run(). The wrappers give you options like forcing/avoiding use of shell (like what IPC::System::Simple offers you), logging the arguments and/or output (using Log::ger), temporarily setting environment variables, temporarily setting working directory, dying on non-zero exit code, capturing (or tee-ing) output (stdout/stderr) (using Capture::Tiny), and a few others. They are meant as a convenience so you can just call system() (or the other wrapper target) instead of doing some additional setup and cleanup yourself. FUNCTIONSsystemUsage: system([ \%opts ], @args) => $child_error ($?) Just like perl's system() except that it accepts an optional hash first argument to specify options. Currently known options:
readpipeUsage: readpipe([ \%opts ], @args) => $output Just like perl's readpipe() (a.k.a. qx() a.k.a. `` a.k.a. the backtick operator) except that it accepts an optional hash first argument to specify options. And it can accept multiple arguments (in which case, the arguments will be quoted for you, including proper quoting on Win32). Known options:
runUsage: run([ \%opts ], @args) => $is_success Like system(), but uses IPC::Run's run(). Known options:
startUsage: start([ \%opts ], @args) => $harness Like run(), but uses IPC::Run's start(). For known options, see run(). HOMEPAGEPlease visit the project's homepage at <https://metacpan.org/release/IPC-System-Options>. SOURCESource repository is at <https://github.com/perlancar/perl-IPC-System-Options>. SEE ALSOIPC::System::Simple also provides wrapper for system() and readpipe() with some additional behavior, although its scope is not as extensive as IPC::System::Options. Proc::Govern similarly provide a run+options function, with a different set of options, including system load watching, logging output to file, disabling and screensaver or power management. AUTHORperlancar <perlancar@cpan.org> CONTRIBUTINGTo contribute, you can send patches by email/via RT, or send pull requests on GitHub. Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via: % prove -l If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me. COPYRIGHT AND LICENSEThis software is copyright (c) 2023, 2021, 2020, 2019, 2017, 2016, 2015 by perlancar <perlancar@cpan.org>. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGSPlease report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=IPC-System-Options> When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
|