Perl: Backtick Errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Backtick Errors
# 1  
Old 10-12-2010
Perl: Backtick Errors

When trying to use backticks for system commands, is there a way to read the error messages if a command doesn't execute properly?
I have no problem getting the results if the command is properly executed.

Ex.

Code:
my @result = `dir`;
foreach my $line (@result) {
     print "Result = $line";
}

But if I were to do an error command (ex. my @result = `asdf`; ), the error message appears on the console, but @result does not "record" that error message.
Is there a way to record that error message?

Many thanks!

Last edited by radoulov; 10-12-2010 at 04:47 PM.. Reason: Code tags, please!
# 2  
Old 10-12-2010
Try:
Code:
@result = `asdf 2>&1`;

# 3  
Old 10-12-2010
Awesome, this is exactly what I needed.
Thanks so much! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Errors running perl statement

When I run this #!/bin/bash Block count: 421958912 Reserved block count: 4219589 perl -e "printf(\"%.1lf%%\n\", ($Reserved block count * 100.0 ) / $Block count);" I get these error messages. Can someone please help me? andyk_~/Downloads$ Show_Percent_Reserved_Blocks.sh... (4 Replies)
Discussion started by: drew77
4 Replies

2. Programming

Please help me understand errors in perl program

co #! /usr/bin/perl use strict; use warnings; use diagnostics; my $amount=""; my $bain; ; my $code=""; my $date;my $day;my $line; my $mo; my $LNUM = 0; my $xyz=""; my $yr; $yr = 2015; my $F; my @F; while (<>) { chop; ++$LNUM; @F = split(';'); if ( $F eq "Date" )... (1 Reply)
Discussion started by: hpk
1 Replies

3. Shell Programming and Scripting

[Solved] Backtick and escapes

Hello all, I have a problem with a bash script. It contains an MySQL query, which when I run it 'as is', executes without a problem. When, however, I try to get it to assign its output to a variable, using the backtick, I get errors. So .. /usr/bin/mysql -N -B mydatabase -e 'SELECT... (3 Replies)
Discussion started by: davidm123SED
3 Replies

4. Programming

Errors in Perl when using awk command

Hi Guys, Hope everyone is fine :) I have this code below: #!/usr/bin/perl $num_of_files=`ls | grep -v remover | wc -l`; $remover=`ls -lrt | grep -v total | grep -v remover | head -1 | awk '{print $8}' | rm \`xargs\``; if ($num_of_files>3) { system ($remover); } When I... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

5. Shell Programming and Scripting

use backtick inside awk

Hello, Can't we use backtick operator inside awk. nawk ' BEGIN { RS=""; FS="\</input\>" } { for(i=1;i<=NF;i++) { if ($i~/\"\"/) { print `grep XYZ $i`; print $i } } } ' test In the following code, I need to print $i and some... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

6. Shell Programming and Scripting

logging errors using perl

Hi, Can some one please tell me how to redirect only errors to the log file using perl. Thanks, Anjan. ---------- Post updated at 08:41 PM ---------- Previous update was at 08:39 PM ---------- Also, i dont want to use any module. Please tell me in normal way (1 Reply)
Discussion started by: Anjan1
1 Replies

7. Shell Programming and Scripting

PERL Syntax Errors

Hi, I am a newbie to PERL and working on a script. When running it I get a lot of compilation errors. The actual command in the program (which is within a case structure) is given below # This gives the actual count of inquires from a log file (It works fine when I type this on the... (2 Replies)
Discussion started by: nurani
2 Replies

8. Shell Programming and Scripting

Perl: combine Backtick & system() I/O operation?

Hi - Within perl I want to execute a system command. I want to re-direct all the output from the command to a file (@result = `$cmd`;), but I ALSO want the results to be displayed on the screen (system("$cmd"); The reason is this - if the command completes, I want to process the output. If the... (6 Replies)
Discussion started by: jeffw_00
6 Replies

9. Shell Programming and Scripting

perl version for syntax errors

All, Does it matter what perl verios your running when you get syntax errors? on version 5.6.1 the code works fine, but on 5.8.0 the code gets errors? #!/usr/bin/perl #use strict; #use warnings; my $mess = 'messages'; my $mess1 = 'messages.1'; my $mess2 = 'messages.2'; my... (13 Replies)
Discussion started by: bigben1220
13 Replies

10. Shell Programming and Scripting

By using awk, how to '(backtick)?

Can I know how to express the '(backtick) in awk?! By typing \' ??? (8 Replies)
Discussion started by: patrick87
8 Replies
Login or Register to Ask a Question