geo has asked for the wisdom of the Perl Monks concerning the following question:

Good Morning,
What is the best way to determine if a Perl script is being run from the command line, or called from another script? I have a suite of scripts in which the program flow will be different depending on how the script was invoked.

I was unable to find a topic discussing this but if I missed, it a pointer would be greatly appreciated.

Thanks for your help
george

  • Comment on I need to determine how a Perl script was invoked

Replies are listed 'Best First'.
Re: I need to determine how a Perl script was invoked
by Illuminatus (Curate) on Nov 15, 2010 at 13:22 UTC

      thanks for the pointer - the information there is just what I was looking for

Re: I need to determine how a Perl script was invoked
by Anonymous Monk on Nov 15, 2010 at 12:51 UTC
    In some cases you can check whether the standard file handles (e.g. STDIN) are connected to a tty:

    $ perl -E 'say -t STDIN ? "interactive":"non-interactive"' interactive
    In other cases, you might want to investigate what the parent process' command line was:

    perl -E 'open F, "/proc/".getppid()."/cmdline" or die $!; $_=<F>; tr/\ +0/ /; say' bash -rcfile .bashrc