in reply to splitting command-line arguments
I'm writing a cron daemon in Perl.
O.K. not really, but sort of. At this point most people should be ready to ask "Why would you want to do something like that?" and the answer is basically, they want to pay me for it (could be worse, they could want me to encode everything Encoding Script).
So, this cron daemon does everything serially so I don't need to worry about any time specifiers, I just have the programs to run in a text file (crontab sort of thing). An entry might look like.
I'm going to want to pass this to system() at some point and I'm having a problem just passing in the complete line. I keep getting"getStuff" configs --force=all --out out.txt -v -a
Yes. Windows. I've punnished my flesh for that too.'D:\Documents' is not recognized as an internal or external command, operable program or batch file.
Here is a simple example of what I want.
This seems to work. Well the thing I snipped it from seems to work but I might have screwed it up pasting it in here.while (<DATA>) { chomp; s/#.*$//; #Clear out comments next unless $_ && $_ ne ''; m/^\s+\Q"\E(.+?)\Q"\E\s*(.*$)/; $task = $1; @args = split /\s+/, $2 if $2; for (my $i = 0; $i < $#args; $i++) { #Arguments begin with - or -- or + if ($args[$i] =~ /^[-\+]/) { #if this looks like an argument, and the next one # doesn't, prepend the next thing to this one. $args[$i] .= " " . $args[$i+1] if $args[$i+1] =~ /^[^-\+]/; #remove the thing from the args array. splice @args, $i+1, 1; } } system ($task, @args); }
If anyone has any suggestions...
Thanks,
Ira
"We demand rigidly defined areas of doubt and uncertainty!"
~Vroomfondel (Hitch Hickers Guide to the Galaxy)
|
|---|