Call the command line function in Perl and get the output as String

What is the best / easiest way to execute a command line function in Perl so that I can get the output as a string?

What I'm actually trying to do is call the Java program from the PL / Perl function in PostgreSQL, and I want the output line, but for now it seems like it just returns 0.

Here is a simple piece of code to explain what I do after:

CREATE OR REPLACE FUNCTION perl_func()
  RETURNS character varying AS
$BODY$    
  return system("java -version");
$BODY$
  LANGUAGE plperlu VOLATILE
  COST 100;
+3
source share
1 answer

You can use backticks. Quote from perldoc perlop:

* qx / STRING /

* `STRING`

, () , /bin/sh . , . ; . ( ) undef, . , ( $/ $INPUT_RECORD_SEPARATOR) , .

system , ( ). :

CREATE OR REPLACE FUNCTION perl_func()
  RETURNS character varying AS
$BODY$
  my $output=`java -version`;
  chomp($output);
  return $output;
$BODY$
  LANGUAGE plperlu VOLATILE
  COST 100;

, backticked , chomp.

+3

All Articles