467,926 Members | 1,721 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

how to get exact command script was ran with

Example:
[PHP]bash$ cmd.pl -m "202.2.13.33 24.32.2.45" -n testing -r "2 3 4 5"[/PHP]

Options are processed by Getppts::Long. I save off @ARGV before it is processed. Unfortunately, the quotes are required because Getopts::Long in the older Perl version we use won't process multiple unquoted params per argument.

now @ARGV contains:
"-m, 202.2.13.33, 24.32.2.45, -n, testing, -r, 2, 3, 4, 5"

I need to have the exact command the user entered to start cmd.pl including the quotes around the parameters for later use so @ARGV is not very helpful here.

Does anyone have a simple trick to accomlish this? So far all I've come up with is a convoluted for loop/regex to reconstruct the string to be "correct", but the user might not have run the script correctly so I really need to stay true here.
Oct 24 '08 #1
  • viewed: 1672
Share:
2 Replies
nithinpes
Expert 256MB
Example:
[PHP]bash$ cmd.pl -m "202.2.13.33 24.32.2.45" -n testing -r "2 3 4 5"[/PHP]

Options are processed by Getppts::Long. I save off @ARGV before it is processed. Unfortunately, the quotes are required because Getopts::Long in the older Perl version we use won't process multiple unquoted params per argument.

now @ARGV contains:
"-m, 202.2.13.33, 24.32.2.45, -n, testing, -r, 2, 3, 4, 5"

I need to have the exact command the user entered to start cmd.pl including the quotes around the parameters for later use so @ARGV is not very helpful here.

Does anyone have a simple trick to accomlish this? So far all I've come up with is a convoluted for loop/regex to reconstruct the string to be "correct", but the user might not have run the script correctly so I really need to stay true here.
One way is:
Expand|Select|Wrap|Line Numbers
  1. $_ =~ s/^(.+\s+.+)$/"$1"/ foreach(@ARGV) ;
  2.  
But if you totally want to avoid using regex and foreach loop, you have to take care while passing arguments to script. It should be like:
Expand|Select|Wrap|Line Numbers
  1.  cmd.pl -m "\"202.2.13.33 24.32.2.45\"" -n testing -r "\"2 3 4 5\""
  2.  
Oct 24 '08 #2
Thanks, that regex is simpler than mine at least. I've even thought of some more really kludgy ways of pulling this off, but in the end I might just use this one liner and damn if the user entered the command incorrectly and didn't read the error he/she was provided at runtime :)
Oct 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Renť | last post: by
16 posts views Thread by diffuser78 | last post: by
16 posts views Thread by John Salerno | last post: by
4 posts views Thread by Keith Hughitt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.