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 myscript.pl the following steps occur:
- The command shell starts the sudo program passing 'sudo' as it first argument, 'perl' as the second, 'myscript.pl' as the third.
- The sudo program then starts perl passing 'perl' as it first argument and 'myscript.pl' 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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Problem in command line arguements
by firearm12 (Novice) on Mar 24, 2012 at 15:36 UTC |
In Section
Seekers of Perl Wisdom