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 7742367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:15:30+00:00 2026-06-01T09:15:30+00:00

Hello guys i need to capture the output of an external command, herefore I

  • 0

Hello guys i need to capture the output of an external command, herefore I use backquotes.
However when the command reaches a newline the output is ommitted. Where $_ = AD

@lines = `"C:/Program Files/Veritas/NetBackup/bin/admincmd/bppllist" $_ -U"`
Test: test1
Test: test2

Test: test3
Test: test4

The actual output:
@lines

Test: test1
Test: test2

Thank you for your time.

    print HTML "<h2 id='pol'>Policy Configuration\n</h2>" ;

  @bpllist =`"$admincmd/bppllist.exe"` or die print "$admincmd/bppllist.exe not found or could not be executed";
foreach (@bpllist) 
{
  print HTML "<div><table class='table'>\n";
  @lines = `"$admincmd/bppllist" $_ -U` or die print       "$admincmd/bpplinfo $_ -U not found or could not be executed";
   print HTML "\t<tr>\n\t<td><b>Policy name: <b></td><td>$_</td>\n\t</tr>\n" ;

  foreach (@lines) {

chop;
 ($var, $value) = split(/:/,$_,2);
 $var = "" if !defined($var);
 $value = "" if !defined($value);
print HTML "\t<tr>\n\t<td>$var</td><td>$value</td>\n\t</tr>\n" ;

  } 
  print HTML "</table></div>";
  }

The output of @bpllist:

  AD
  Sharepoint
  Echchange
  Vmware
  • 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-01T09:15:32+00:00Added an answer on June 1, 2026 at 9:15 am

    Here’s how to capture the STDOUT & STDERR of a spawned process using backticks:

    my $output = join('', `command arg1 arg2 arg3 2>&1`);
    

    How it works has no dependence whatsoever on newlines in the output of command.

    If you also need to send text to command‘s STDIN, then use IPC::Open3.


    Cleaned your code up a bit. It works for me.

    use strict;
    use warnings;
    use 5.10.0;
    
    # something missing here to set up HTML file handle
    # something missing here to set up $admincmd
    
    print HTML q{<h2 id='pol'>Policy Configuration\n</h2>};
    my @bpllist = `"$admincmd/bppllist.exe"` 
      or die "$admincmd/bppllist.exe not found or could not be executed\n";
    for my $policy (@bpllist) {
      print HTML q{<div><table class='table'>\n};
      my @lines = `$admincmd/bpplinfo.exe $policy -U 2>&1`;
      print HTML qq{\t<tr>\n\t<td><b>Policy name: <b></td><td>$policy</td>\n\t</tr>\n} ;
      for my $pair (@lines) {
        chomp($pair); # only remove newlines, not other characters
        my ($var, $value) = split /:/, $pair, 2;
        $var //= '';
        $value //= '';
        print HTML qq{\t<tr>\n\t<td>$var</td><td>$value</td>\n\t</tr>\n} ;
      }
      print HTML q{</table></div>};
    }
    

    Update 2

    You appear to be doing this on windows?

    I don’t think the 2>&1 trick will work there.

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

Sidebar

Related Questions

hello guys i need to use pure SQL queries for my database project at
hello guys i need to sort some elements of integer in an integer array
hello guys i am try to print the output of two element data simultaneously
Hello guys I need to pass a string array over to a setter that
Hello guys I am working on a prolog game and I need to write
Hello guys I'm stucked in a point and I need your help. I want
Hello guys i'm making a little app in which i need to enumerate all
hello guys i need small help in understanding file system of android Now in
Hello friendly guys. On Linux with Bash, I often need to list environment variables(env-var)
Hello guys I need a bit of help. As I am not very good

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.