perlorg-modeorg-babel

Is there a way to execute a file and one line of program in perl?


I want to execute some code before execution(redirect stderr to stdout).

perl -e "BEGIN {open STDERR, '>&STDOUT'}" perl.pl

But when there is -e, no file will be executed. I know $Config{sitelib}/sitecustomize.pl can pre-execute some code, and -f option can disable it. But this way is inflexible. In most cases, I do not need to add extra code. I don't want to add -f every time.

I cannot use shell to redirect. I want to set org-babel-perl-command in emacs org mode so that stdout and stderr can be printed in the same way, instead of opening another window to print stderr. org-babel-perl-command should be like perl.

For example, org-babel-python-command can be set to python -i -c "import sys; sys.stderr = sys.stdout".


Solution

  • perl -e'
       open( STDERR, ">&STDOUT" );
       do( shift( @ARGV ) );
    ' perl.pl
    

    (Error handling needed.)

    For the case in question, the following would suffice:

    perl perl.pl 2>&1
    

    Maybe even

    ./perl.pl 2>&1