Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Finding what args were passed to the perl interpretter ?

by almut (Canon)
on Nov 19, 2008 at 23:43 UTC ( #724761=note: print w/replies, xml ) Need Help??


in reply to Finding what args were passed to the perl interpretter ?

(Update: I hadn't seen your follow-up note about the -d:NYTProf before posting this... If you need to do it from within the Perl code itself, this of course wouldn't work.)

___

You could use the respective system call tracing tool, e.g. on Linux:

$ strace -e execve -s 200 perl -le '$/ = "\0"; open my $fh, "/proc/$$/ +cmdline"; print for <$fh>' execve("/usr/local/bin/perl", ["perl", "-le", "$/ = \"\\0\"; open my $ +fh, \"/proc/$$/cmdline\"; print for <$fh>"], [/* 71 vars */]) = 0

(add the option -f in a more complex setup, where perl is being called somewhere further down the fork-exec line...)

Other systems have other system call tracers  (see this node for an attempt of mine to put together a list).

This approach isn't really portable either... but you should at least be able to get it working somehow — which you otherwise couldn't if there's no /proc file system.

Replies are listed 'Best First'.
Re^2: Finding what args were passed to the perl interpretter ?
by dpuu (Chaplain) on Nov 20, 2008 at 00:19 UTC
    How would a perl script attach an strace to itself in such a way that it can see its own invocation? If I simply do system "strace -p $$" then it's too late (the execve occurred in the past!)
    --Dave
    Opinions my own; statements of fact may be in error.

      Well, the idea would be to attach strace to whatever is calling perl... Why would you want to do it from within the script itself?

        See my previous post: I was wanting the script to figure out if it was invoked using "-d:NYTProf". I like JavaFan's approach of checking if Devel::NYTProf->can("import") -- though obviously that's not ideal.

        I was sort of hoping to answer the more general problem: some form of auto-populated $PERL5OPTS that I can use in much the same way as ${MAKE} in recursive makefiles. But the specific answer is good for now

        --Dave
        Opinions my own; statements of fact may be in error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2023-12-10 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (39 votes). Check out past polls.

    Notices?