|
NameOpenXPKI::Crypto::CLIDesriptionThis module is an ABSTRACT superclass that implements basic handling of calling command line binarys. Note that it can not be instantiated.FunctionsSTARTThe new function creates a new instance of this class. There are the following parameters:
prepareThis prepares a command array to be executed. The only parameter is COMMAND which must either contain a string or an array reference. The parameter is appended to the shell command.executeperforms the commands. It throws an exception on error. The behaviour of this function is a little bit difficult. The simplest way is that you use the function without any arguments. This means that you have passed all parameters via the command line parameters and you get the the result via the function get_result or you used an explicit output file.Example: $cli->execute(); The function supports another way too. Sometimes it is necessary to pass input directly or to read the output directly beause it is critical data which should never be stored on a disk. You can use the parameter PARAMS in this case. You have to specify for each command which you specified via prepare a type and if necessary the data. Example: $cli->prepare ({COMMAND => ["command1 -params ...", "command2 -params ...", "command3 -params ...", "command4 -params ..."]}); my $params = [ {TYPE => "STDIN", DATA => "the input data"}, {TYPE => "STDOUT"}, {TYPE => "NOTHING"}, {TYPE => "STDOUT"}, ]; my $result = $cli->execute ({PARAMS => $params}); The first command is an example for using STDIN. The specified data will be passed via STDIN to the command. The second command passes the result via STDOUT directly into the code. This means that $result contains the result from the queries two and four. If you need the results seperately the please look into $params->[1]->{STDOUT} and $params->[3]->{STDOUT}. The third query simply enforces normal behaviour via files. get_resultreturns the result of the commands which were executed with run_cmd. If there was no output then 1 will be returned.set_environmentThis function is to be implemented by children classes. It is executed right before the command is executed, so shell environment variables that are relevant for the command can be set here (e.g. OPENSSL_CONF in the OpenSSL case).error_ispresentThis function is to be implemented by the children classes. It gets the STDERR output as a string, which it can parse for errors. Depending on whether there are errors or not, it has to return true or false.Examplemy $cli = OpenXPKI::Crypto::Backend::OpenSSL::CLI->new ({ TMP => "/tmp", SHELL => "/usr/local/ssl/bin/openssl", ENGINE => $engine }); $cli->prepare ({COMMAND => ['x509 -in cert.pem -outform DER -out cert.der']}); $cli->execute (); ## senseless here because the result is in cert.der ## $cli->get_result(); undef $cli; ## now do something with cert.derSee alsoOpenXPKI::Crypto::Backend::OpenSSL::CLI - The CLI class for OpenSSL OpenXPKI::Crypto::Tool::SCEP::CLI - The CLI class for openca-scep
Visit the GSP FreeBSD Man Page Interface. |