Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Can't get errpr message from back quoted command

hi all,

     my perl commands are like this
 
     $out = `zzzzzz`;    
     print("Error : $out");

where 'zzzzzz' is not a system command. That's why it should generate error.
Means $out should contain error as "Can't exec "zzzzzz": No such file or directory at ./test.pl line 2.". Instead $out contain nothing.

    I can redirect errors to file using STDERR with open(..). But I dont' want this way.


    Please help me in this regard.
 
    With warm regards
    -Mahesh
0
smpoojary
Asked:
smpoojary
  • 3
  • 3
1 Solution
 
ozoCommented:
$out = `zzzzzz 2>&1 >/dev/null`;
0
 
smpoojaryAuthor Commented:
hi ozo,

    I want error message in $out. Means $out should contain "bash: zzzzzzz: command not found".
   -Mahesh
0
 
TintinCommented:
$out = `bash zzzz 2>&1`;


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
smpoojaryAuthor Commented:
hi,
      You didn't understand my question.

If I run the following command
     $cmd = "date";
     $out = `$cmd`;     Then $out should contain "Fri Apr 22 14:42:36 GMT 2005". This  is working fine.

If I run the following command
    $cmd = `zzzzzz`;
    $out = `$cmd`;     Then $out should contain "zzzzzz: command not found". But in this $out contains nothing.

    Please help me out in this regard.

    With warm regards
    -Mahesh

 
0
 
ozoCommented:
$out = `zzzzzz 2>&1 >/dev/null`;
$out contains "sh: zzzzzz: command not found\n"

$out = `bash -c "zzzzzz" 2>&1 >/dev/null`;
$out contains "bash: zzzzzz: command not found\n"

0
 
ozoCommented:
$out = `zzzzzz 2>&1 | cat`;
0
 
smpoojaryAuthor Commented:
hi ozo,

     Thanks a lot.  The command you gave above is working properly. Thanks to Tintin also.

     with warm regards
     -Mahesh
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now