Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Problem in command line arguements

by BrowserUk (Pope)
on Mar 23, 2012 at 06:55 UTC ( #961158=note: print w/ replies, xml ) Need Help??

in reply to Problem in command line arguements

Is there any variable which stores the parameter passed before the actual script name

No. That information is not available anywhere within your perl script.

When you type the command line sudo perl the following steps occur:

  1. The command shell starts the sudo program passing 'sudo' as it first argument, 'perl' as the second, '' as the third.
  2. The sudo program then starts perl passing 'perl' as it first argument and '' as the second.

Perl is never aware of the original first argument.

However, there are a couple of approaches you might use to discover it:

  • If your OS provides an api that allows you to screen-scrape the terminal session, that might work.

    For example, on windows you could use Win32::Console::ReadRect() to grab the text from the terminal window. You could then search it for the line containing your script name.

  • Alternatively, you could use getppid to obtain the pid of your parent process.

    With that, most OSs provide a mechanism for finding out the name of the process with that pid.

    On windows you might use Win32::Process::Info, or grep the output of the tasklist command.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Comment on Re: Problem in command line arguements
Select or Download Code
Re^2: Problem in command line arguements
by firearm12 (Novice) on Mar 24, 2012 at 15:36 UTC
    Thanks very much for your response.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-09-22 12:15 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (191 votes), past polls