What is the best/easiest way to execute a command line function in Perl, such that I can get the output as a String?
What I'm actually trying to do is call a Java program from within a PL/Perl function in PostgreSQL, and I want the output String, however at the moment it seems to just be returning 0.
Here is a simple piece of code to explain what I am after:
CREATE OR REPLACE FUNCTION perl_func()
RETURNS character varying AS
$BODY$
return system("java -version");
$BODY$
LANGUAGE plperlu VOLATILE
COST 100;
You can use backticks. Quoting from
perldoc perlop
:You can't use
system
for this, since it just returns the return value of the argument (when run as a shell command). This should work:Note that the output of a backticked command usually includes a trailing newline, so it's often useful to get rid of that via
chomp
.