Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: did you mean python

by Anonymous Monk
on Jan 29, 2026 at 04:01 UTC ( [id://11167260]=note: print w/replies, xml ) Need Help??


in reply to Re^4: did you mean python
in thread did you mean python

> How do I silence the error message from perl?

I just changed this line

printf("It parses as Perl so I am running it ...\n");
to this
fprintf(stderr, "It parses as Perl so I am running it ...\n");
so i can silence or redirect stderr with 2>&1- or 2>logfile

Replies are listed 'Best First'.
Re^6: did you mean python
by bliako (Abbot) on Jan 29, 2026 at 12:00 UTC

    Anon, with your redirection you will mix stderr messages from PARSING your input script (as perl, with perl_parse()) with stderr messages from RUNNING it (if it is indeed perl, with perl_run()). What I mean is that if your script, for example, fails to find a file during runtime, this will go to the logger file, mixed with all the possible syntax errors while assessing if perl or python. Well it is a solution.

    However, if you use the latest version of what I provided (see the modified C program in here: Re: did you mean python), you will have the syntax errors (via stderr) redirected to a logger file and then stderr will be reinstated to what it usually is so that you will have the runtime errors to your terminal. This behaviour is controlled by an env variable. You can modify the C program to provide the logger filename with another env variable.

    bw, bliako

Re^6: did you mean python
by Anonymous Monk on Jan 29, 2026 at 04:10 UTC
    In the original version of the program:
    /* python.c - 27/01/2026 by bliako (bliako at cpan org) for https://perlmonks.org/?node_id=11167241 Run it either with a Perl CLI and a Perl script, like you would normally do with perl script.pl, perl -e ... etc. or with a python CLI and a python script. If the script does not parse as valid Perl code, it will pass the CLI and the script to a python interpreter. CAVEAT: it will fallback to python if your script is Perl but has syntax errors. compile it with: gcc python.c -o python `perl -MExtUtils::Embed -e ccopts -e ldopt +s` */ #include <EXTERN.h> /* from the Perl distribution */ #include <perl.h> /* from the Perl distribution */ static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ /* You gotta love Perl */ int main(int argc, char **argv, char **env) { PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; int ret = perl_parse(my_perl, NULL, argc, argv, (char **)NULL); if( ret ){ perl_destruct(my_perl); perl_free(my_perl); // add here language detection logic, // various options available open source fprintf(stderr, "I guess it is &*^#$* pyton /sic/ ...\n"); execvpe("/usr/bin/python", argv, env); } printf("It parses as Perl so I am running it ...\n"); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); exit(EXIT_SUCCESS); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11167260]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2026-04-18 01:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.