in reply to Re: Capture error from one-liner
in thread Capture error from one-liner

Sure. Below is an example where the filename is not found. In this case i'd like to be able to capture an error and know that it failed.

perl -i.bak -pe 's/AJZ/AZZ/g if /^AB/' J_BB@ Can't open J_BB@: No such file or directory. echo $? 0

Replies are listed 'Best First'.
Re^3: Capture error from one-liner
by LanX (Saint) on Sep 19, 2014 at 16:32 UTC
    not an expert of korn-shell, but what you want is capturing STDERR.

    If there is no direct way to do it, but you could redirect STDERR to STDOUT and capture STDOUT.

    No idea if you need backticks° in ksh then!¹

    (I would do the whole task completely within Perl not in ksh²)

    HTH (otherwise others will know =)

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    updates

    °) ksh seems to support $() for backticks

    ¹) normally errors are piped into a file like here, bash can use backticks to capture STDOUT

    ²) should be mentioned that this is not a Perl question!