Re: [MSH] More Function

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Keith Hill wrote:
"/\/\o\/\/" <no@xxxxxxxx> wrote in message news:uXXUaxG6FHA.3136@xxxxxxxxxxxxxxxxxxxxxxx

thx, I have the Definition, it will show up normaly,only I can not find where it is defined. (in any profile file) so I got curious

But I can overrule it in my Profile, that is the Most important part ;-)
(as it is a bit limited)

I wrote a new one that :

1) will NOT leave his StatusMessages around messing up the output

2) Will show the filePosition as Percentage

3) Supports the P Command that let's YOU give a number of lines

4) Supports the = Command that gives you the current Linenumber

5) Supports the F Command that skips to the next file.

6) Supports the -C argument to clear the Screen First.

Who is interested can find it here :

http://mow001.blogspot.com/2005/11/enhanced-more-function-for-msh.html


Nice work! This does point out one deficiency in the MSH script language: the lack of C#'s using statement for disposing disposable objects. The problem with your current implementation is that once you run it on a file you can no longer write to that file in the MSH session. You need to sprinkle some $fs.Close calls in your code everywhere where you exit the function e.g.:

"Q" {$fs.Close();$eof = $true;$Quit = $true}

A "using" block would allow you to grab the $fs variable and then no matter how the using block is exited (exception or normally) the variable will get disposed e.g.:

using ($fs = (get-item $file).OpenText()) {
    ....
}

--
Keith


Did you check, if using the OpenText it will close after getting out of scope (and does this locking problem, only goes for the lastfile, or all files)?

(as the SB does count the bytes also, you can also Add that value after every page written to get the value) than you can use the textreader.)
but as I did not care much about performance (viewing per page), I just took this solution to get the Position working (also had some Double newline problems, so maybe I should go back to the OpenText.).


but ofcourse, You right about the Closing of the Files, I should make that more of a habbit.(as i'm not a programmer I tend to be a bit careless with releasing, just counting on it to get out of scope.)especialy when I'm just reading.

Also the Ctrl-C I should handle myself I think to get this done.
(does I ugly exit now)

also nice was the difference between the ReadKey of Console and of the $host Object.(in handeling shift / control)

also I'm still a bit finding my "style" in MSH and expect to change it for the coming time,i never intended it to be production quality, but keeping files locked after the function is gone out of scope is not good, I will look into that.

thx for the remark, did not see this yet.

gr /\/\o\/\/

.



Relevant Pages

  • Re: Dynamic scope
    ... MSH uses dynamic lookup of variables but by default we use copy-on-write ... If you want to modify a specific scope you ... Microsoft Command Shell Development ...
    (microsoft.public.windows.server.scripting)
  • MSH: Dynamic scope
    ... At one time wasn't there a dynamic scoping feature in MSH? ... shell variable can be overriden at a particular scope and then the new value ... Prev by Date: ...
    (microsoft.public.windows.server.scripting)