Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read standard out into a variable 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
0
0
US
I'm running a command line program which spits a bunch of information back, and I want to read this into a variable. Is there a way to do this other than redirecting standard out to a file and reading the file in? That's how I'm doing it now, and it's fine, just a little clunky, so I thought I'd ask.

Thanks,
Rob
 
Try something like this:
Code:
SH = CreateObject("WScript.Shell")
Set X = SH.Exec("YourProg")
Do While X.Status = 0
  WScript.Sleep 100
Loop
While Not X.StdOut.AtEndOfStream Then
  sLine = X.StdOut.ReadLine
  ...
Wend
You can also use the StdErr property

Hope This Help
PH.
 
Why the necessity to sleep? Does this little trick of sleeping in any way degrade the reliability?

I have the option of writing to a file, so if this is in any way less reliable I can't take it as a viable solution.

Thanks for the idea, I will run it through some tests and see what happens.

-Rob
 
nevermind that question, after typing it in I realize you're just waiting for the program to end before processing the StdOut
 
This doesn't seem to work on w2k pro... works dandy in XP pro, but 2k never realizes the change in status of my program. (However, if I just add a >> somefile to my command, then it realizes it completes)

Any ideas?

-Rob
 
Confirm that the version of WSH on your 2k machine is 5.6. 2k originally came with version 2 which didn't have this functionality
 
Yeah, I've upgraded that for other functionallity. My final interpretation of the above was that it was great and worked most of the time. But on certain commands it just didn't. My guess is the commands aren't returning properly. For example, the type command.... works for files of certain sizes but not others, so maybe an overflow issue.

I found another way which holds up under more diverse conditions... basically I just output ( >> filename.txt) my command and then read in the contents of the file with an FSO object... sloppy by effective. Thanks for the help.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top