• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • 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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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