Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:03:40+00:00 2026-06-02T13:03:40+00:00

What is the best/easiest way to execute a command line function in Perl, such

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:03:42+00:00Added an answer on June 2, 2026 at 1:03 pm

    You can use backticks. Quoting from perldoc perlop:

    *qx/STRING/

    *`STRING`

    A string which is (possibly) interpolated and then
    executed as a system command with /bin/sh or its equivalent. Shell
    wildcards, pipes, and redirections will be honored. The collected
    standard output of the command is returned; standard error is
    unaffected. In scalar context, it comes back as a single (potentially
    multi-line) string, or undef if the command failed. In list context,
    returns a list of lines (however you’ve defined lines with $/ or
    $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.

    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:

    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;
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know the best/easiest way to get a visual diff of a
Can anyone please recommend the best and easiest way to include multiple Javascript files
I was wondering what the best and easiest way was to ensure that the
I'm looking for the best/easiest way to add extensions to an existing protocol (can't
What is the best and easiest way to send a string from one instance
What is the best/easiest way to build a minimal task queue system for Linux
What is the best/easiest way to sort a large list of words (10,000-20,000) by
Whats the best/easiest way to test for administrative rights in a PowerShell script? I
In ANSI C on Windows what is the best/easiest way to transfer data between
I did some research into the easiest/best way to generate a pdf in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.