Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


extended Textstream and WScript.Shell -- oh dear!

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,26094
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> extended Textstream and WScript.Shell -- oh dear!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 extended Textstream and WScript.Shell -- oh dear! - 9/19/2005 6:54:43 PM   
  x0000FF

 

Posts: 5
Score: 0
Joined: 9/19/2005
Status: offline
Hello all!

I've done a bunch of searching and reading through this forum to try and fix a pesky bug in a set of scripts i'm writing; but haven't managed to sort it out :(

I'm building a custom class called uProcess, which extends the WScript.Shell object


      

The code above is a snippet from inside my 'Status' function.. in the code snipped-out it simply takes the data read and writes it to a textstream


Now everything here works fine, unless StdOut is 'empty' ... which is why there is such a strange do, loop....
i'm hopeless at explaining these things, but my problem is as follows:

* execute "cmd /c pause"       [ (press any key to continue . . . )  ]
* script starts processing text sent to StdOut and storing it in a seperate textstream
* process is now waiting for input, and nothing is being written to StdOut
* script checks to see if "AtEndOfStream" for StdOut, and hangs.


Does anyone know of a way I can check to see if m_oExec.StdOut is empty?   I thought that by using an 'AtEndOfStream' test I would be able to read from the buffer until it reached the end..

again sorry for terminology, coding style etc.. i'm not a programmer.
 
 
Post #: 1
 
 RE: extended Textstream and WScript.Shell -- oh dear! - 9/20/2005 1:10:09 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Maybe it would be better if you explain what you are trying to accomplish. Trying to write and read to and from StdOut and StdIn, while possible is often more difficult than it needs to be. Perhaps there is a way to accomplish your goals without using them at all.

(in reply to x0000FF)
 
 
Post #: 2
 
 RE: extended Textstream and WScript.Shell -- oh dear! - 9/20/2005 10:36:28 AM   
  x0000FF

 

Posts: 5
Score: 0
Joined: 9/19/2005
Status: offline
Ok thanks, i'll try this one again :)


I've been building a function suite to interface with some software we use in house (development studio)
more specifcally, the scripts will be integrated into 'Perforce' the sub-version control program

I have some utilities such as:

uString.vbs
 Object based wrapper for the existing Variant value type string. Implemented to suppor a more
 consistent intuitive string type.


and then:

uStringStream.vbs
Which is in the same style as the uString script above, and provides full polymorphisism with true text stream objects


now we have

uProcess.vbs

Which is used to execute a command, and perform all the IO operations; but capture the data and store it in uStringStream objects.

The TextStream used to store the data is initialized as such:


      

Then in uProcess here is my 'Execute' method


      



now further into the uProcess, I have Get Status, which as can be seen in my first post, is like what i'd call a "run time loop"  no idea what the real terminology is...
basically it gets called repeatedly until the process throws out a 1, and in doing so processes the streams and flushes them into the textstream objects I mentioned earlier.

I've cut down my status property alot so it's only dealing with output right now.


      


so now to actually use these functions, in a testing script:


      



Obviously, Status will never reach 1, as the process is waiting for a key input (press any key to continue)
but that's not the problem, the problem is that it will read
"Press any key to continue . . . " from the StdOut stream, then hang there at the "AtEndOfStream" test.

I'm not good at explaining this but i've tried my best, and i've rtfm, and quite possibly every piece of documentation i can find on vbscript.  and i'm lost.

It may take 4 or 5 goes, but I can try and explain more if this is still really ambiguous.

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: extended Textstream and WScript.Shell -- oh dear! - 9/21/2005 4:50:21 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
x0000FF, maybe this is what you are asking.

Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("test.bat")
input = ""

Do While True
     If Not oExec.StdOut.AtEndOfStream Then
          input = input & oExec.StdOut.Read(1)
          If InStr(input, "Press any key") <> 0 Then Exit Do
          End If
     WScript.Sleep 100
     Loop
oExec.StdIn.Write VbCrLf

Do While oExec.Status <> 1
     WScript.Sleep 100
      Loop


It looks quite a lot as your script part, but there are minor differences.
You can judge for yourself if this gives a solution.

The source is Windows Script Technologies
© 2001 Microsoft Corporation. All rights reserved.
Build: Topic Version 5.6.9309.1546


Regards.

< Message edited by didorno -- 9/21/2005 4:53:02 AM >


_____________________________

Regular Expression ? I (L+o{1,}v{1,3}e\s)+[iI]t!$

(in reply to x0000FF)
 
 
Post #: 4
 
 RE: extended Textstream and WScript.Shell -- oh dear! - 9/21/2005 9:40:36 AM   
  x0000FF

 

Posts: 5
Score: 0
Joined: 9/19/2005
Status: offline
Yeah, I got the idea to try using 'Pause' from that sample on MSDN..  it's a good way to check if input and output are able to work in synchronization

If you notice, i'm not doing anything different in my script as they are in theirs; therefore if their code is used to read the full line of console output it will also crash.


      

this is how they're preventing their script from crashing, you see it's exiting the DO loop when it finds "Press any key" ; StdOut will still have " to continue . . . " in it.

If you took that test out, it will crash; but what if you wanted to capture all of it?

I can't understand what the use of StdOut,In,Err are if i'm unable to read correctly from them.

At the very most basic forms of what I need to do is after launching a process, I need to be able to capture everything sent to StdOut and store it in a TextStream

My code will do that fine, for example if you change it to exec "cmd /c dir %windir%" then it will read all that in and store it in the textstream.

But in a situation, such as when the process is waiting for input, absolutely ANY functions performed on StdOut cause the code to hang, like StdOut is null or something

So that's the end? :(   ah no, what am I going to do.. 


      

I totally shouldn't have left this one till last ;)

(in reply to didorno)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> extended Textstream and WScript.Shell -- oh dear! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts