ipc::cmd.3
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· 3 代码 · 共 405 行 · 第 1/2 页
3
405 行
.ie n .Sh "$bool = IPC::Cmd\->can_capture_buffer".el .Sh "\f(CW$bool\fP = IPC::Cmd\->can_capture_buffer".IX Subsection "$bool = IPC::Cmd->can_capture_buffer"Utility function that tells you if \f(CW\*(C`IPC::Cmd\*(C'\fR is capable ofcapturing buffers in it's current configuration..SH "FUNCTIONS".IX Header "FUNCTIONS".ie n .Sh "$path = can_run( \s-1PROGRAM\s0 );".el .Sh "\f(CW$path\fP = can_run( \s-1PROGRAM\s0 );".IX Subsection "$path = can_run( PROGRAM );"\&\f(CW\*(C`can_run\*(C'\fR takes but a single argument: the name of a binary you wishto locate. \f(CW\*(C`can_run\*(C'\fR works much like the unix binary \f(CW\*(C`which\*(C'\fR or the bashcommand \f(CW\*(C`type\*(C'\fR, which scans through your path, looking for the requestedbinary ..PPUnlike \f(CW\*(C`which\*(C'\fR and \f(CW\*(C`type\*(C'\fR, this function is platform independent andwill also work on, for example, Win32..PPIt will return the full path to the binary you asked for if it wasfound, or \f(CW\*(C`undef\*(C'\fR if it was not..ie n .Sh "$ok\fP | ($ok, \f(CW$err\fP, \f(CW$full_buf\fP, \f(CW$stdout_buff\fP, \f(CW$stderr_buff) = run( command => \s-1COMMAND\s0, [verbose => \s-1BOOL\s0, buffer => \e$SCALAR] );".el .Sh "\f(CW$ok\fP | ($ok, \f(CW$err\fP, \f(CW$full_buf\fP, \f(CW$stdout_buff\fP, \f(CW$stderr_buff\fP) = run( command => \s-1COMMAND\s0, [verbose => \s-1BOOL\s0, buffer => \e$SCALAR] );".IX Subsection "$ok | ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = run( command => COMMAND, [verbose => BOOL, buffer => $SCALAR] );"\&\f(CW\*(C`run\*(C'\fR takes 3 arguments:.IP "command" 4.IX Item "command"This is the command to execute. It may be either a string or an arrayreference.This is a required argument..SpSee \s-1CAVEATS\s0 for remarks on how commands are parsed and theirlimitations..IP "verbose" 4.IX Item "verbose"This controls whether all output of a command should also be printedto \s-1STDOUT/STDERR\s0 or should only be trapped in buffers (\s-1NOTE:\s0 buffersrequire \f(CW\*(C`IPC::Run\*(C'\fR to be installed or your system able to work with\&\f(CW\*(C`IPC::Open3\*(C'\fR)..SpIt will default to the global setting of \f(CW$IPC::Cmd::VERBOSE\fR,which by default is 0..IP "buffer" 4.IX Item "buffer"This will hold all the output of a command. It needs to be a referenceto a scalar.Note that this will hold both the \s-1STDOUT\s0 and \s-1STDERR\s0 messages, and youhave no way of telling which is which.If you require this distinction, run the \f(CW\*(C`run\*(C'\fR command in list contextand inspect the individual buffers..SpOf course, this requires that the underlying call supports buffers. Seethe note on buffers right above..PP\&\f(CW\*(C`run\*(C'\fR will return a simple \f(CW\*(C`true\*(C'\fR or \f(CW\*(C`false\*(C'\fR when called in scalarcontext.In list context, you will be returned a list of the following items:.IP "success" 4.IX Item "success"A simple boolean indicating if the command executed without errors ornot..IP "errorcode" 4.IX Item "errorcode"If the first element of the return value (success) was 0, then someerror occurred. This second element is the error code the commandyou requested exited with, if available..IP "full_buffer" 4.IX Item "full_buffer"This is an arrayreference containing all the output the commandgenerated.Note that buffers are only available if you have \f(CW\*(C`IPC::Run\*(C'\fR installed,or if your system is able to work with \f(CW\*(C`IPC::Open3\*(C'\fR \*(-- See below).This element will be \f(CW\*(C`undef\*(C'\fR if this is not the case..IP "out_buffer" 4.IX Item "out_buffer"This is an arrayreference containing all the output sent to \s-1STDOUT\s0 thecommand generated.Note that buffers are only available if you have \f(CW\*(C`IPC::Run\*(C'\fR installed,or if your system is able to work with \f(CW\*(C`IPC::Open3\*(C'\fR \*(-- See below).This element will be \f(CW\*(C`undef\*(C'\fR if this is not the case..IP "error_buffer" 4.IX Item "error_buffer"This is an arrayreference containing all the output sent to \s-1STDERR\s0 thecommand generated.Note that buffers are only available if you have \f(CW\*(C`IPC::Run\*(C'\fR installed,or if your system is able to work with \f(CW\*(C`IPC::Open3\*(C'\fR \*(-- See below).This element will be \f(CW\*(C`undef\*(C'\fR if this is not the case..PPSee the \f(CW\*(C`HOW IT WORKS\*(C'\fR Section below to see how \f(CW\*(C`IPC::Cmd\*(C'\fR decideswhat modules or function calls to use when issuing a command..SH "HOW IT WORKS".IX Header "HOW IT WORKS"\&\f(CW\*(C`run\*(C'\fR will try to execute your command using the following logic:.IP "\(bu" 4If you have \f(CW\*(C`IPC::Run\*(C'\fR installed, and the variable \f(CW$IPC::Cmd::USE_IPC_RUN\fRis set to true (See the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR Section) use that to execute the command. You will have the full output available in buffers, interactive commands are sure to work and you are guaranteed to have your verbositysettings honored cleanly..IP "\(bu" 4Otherwise, if the variable \f(CW$IPC::Cmd::USE_IPC_OPEN3\fR is set to true (See the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR Section), try to execute the command using\&\f(CW\*(C`IPC::Open3\*(C'\fR. Buffers will be available on all platforms except \f(CW\*(C`Win32\*(C'\fR,interactive commands will still execute cleanly, and also your verbositysettings will be adhered to nicely;.IP "\(bu" 4Otherwise, if you have the verbose argument set to true, we fall backto a simple \fIsystem()\fR call. We cannot capture any buffers, butinteractive commands will still work..IP "\(bu" 4Otherwise we will try and temporarily redirect \s-1STDERR\s0 and \s-1STDOUT\s0, do a\&\fIsystem()\fR call with your command and then re-open \s-1STDERR\s0 and \s-1STDOUT\s0.This is the method of last resort and will still allow you to executeyour commands cleanly. However, no buffers will be available..SH "Global Variables".IX Header "Global Variables"The behaviour of IPC::Cmd can be altered by changing the followingglobal variables:.ie n .Sh "$IPC::Cmd::VERBOSE".el .Sh "\f(CW$IPC::Cmd::VERBOSE\fP".IX Subsection "$IPC::Cmd::VERBOSE"This controls whether IPC::Cmd will print any output from thecommands to the screen or not. The default is 0;.ie n .Sh "$IPC::Cmd::USE_IPC_RUN".el .Sh "\f(CW$IPC::Cmd::USE_IPC_RUN\fP".IX Subsection "$IPC::Cmd::USE_IPC_RUN"This variable controls whether IPC::Cmd will try to use IPC::Runwhen available and suitable. Defaults to true if you are on \f(CW\*(C`Win32\*(C'\fR..ie n .Sh "$IPC::Cmd::USE_IPC_OPEN3".el .Sh "\f(CW$IPC::Cmd::USE_IPC_OPEN3\fP".IX Subsection "$IPC::Cmd::USE_IPC_OPEN3"This variable controls whether IPC::Cmd will try to use IPC::Open3when available and suitable. Defaults to true..ie n .Sh "$IPC::Cmd::WARN".el .Sh "\f(CW$IPC::Cmd::WARN\fP".IX Subsection "$IPC::Cmd::WARN"This variable controls whether run time warnings should be issued, likethe failure to load an \f(CW\*(C`IPC::*\*(C'\fR module you explicitly requested..PPDefaults to true. Turn this off at your own risk..SH "Caveats".IX Header "Caveats".IP "Whitespace" 4.IX Item "Whitespace"When you provide a string as this argument, the string will besplit on whitespace to determine the individual elements of yourcommand. Although this will usually just Do What You Mean, it maybreak if you have files or commands with whitespace in them..SpIf you do not wish this to happen, you should provide an arrayreference, where all parts of your command are already separated out.Note however, if there's extra or spurious whitespace in these parts,the parser or underlying code may not interpret it correctly, andcause an error..SpExample:The following code.Sp.Vb 1\& gzip \-cdf foo.tar.gz | tar \-xf \-.Ve.Spshould either be passed as.Sp.Vb 1\& "gzip \-cdf foo.tar.gz | tar \-xf \-".Ve.Spor as.Sp.Vb 1\& [\*(Aqgzip\*(Aq, \*(Aq\-cdf\*(Aq, \*(Aqfoo.tar.gz\*(Aq, \*(Aq|\*(Aq, \*(Aqtar\*(Aq, \*(Aq\-xf\*(Aq, \*(Aq\-\*(Aq].Ve.SpBut take care not to pass it as, for example.Sp.Vb 1\& [\*(Aqgzip \-cdf foo.tar.gz\*(Aq, \*(Aq|\*(Aq, \*(Aqtar \-xf \-\*(Aq].Ve.SpSince this will lead to issues as described above..IP "\s-1IO\s0 Redirect" 4.IX Item "IO Redirect"Currently it is too complicated to parse your command for \s-1IO\s0Redirections. For capturing \s-1STDOUT\s0 or \s-1STDERR\s0 there is a work aroundhowever, since you can just inspect your buffers for the contents..SH "See Also".IX Header "See Also"\&\f(CW\*(C`IPC::Run\*(C'\fR, \f(CW\*(C`IPC::Open3\*(C'\fR.SH "ACKNOWLEDGEMENTS".IX Header "ACKNOWLEDGEMENTS"Thanks to James Mastros and Martijn van der Streek for theirhelp in getting IPC::Open3 to behave nicely..SH "BUG REPORTS".IX Header "BUG REPORTS"Please report bugs or other issues to <bug\-ipc\-cmd@rt.cpan.org>..SH "AUTHOR".IX Header "AUTHOR"This module by Jos Boumans <kane@cpan.org>..SH "COPYRIGHT".IX Header "COPYRIGHT"This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?