Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Vbscript which will read text in a command windows and assign a value to a variable

Posted on 2009-04-15
6
241 Views
Last Modified: 2013-11-10
Hello,

I need a Vbscript which will read text in a command windows and assign a value to a variable within the script.
Let's say a simple example of if I run a command in a CMD windows and if gives me output to a line like:
            Name: Jim Black  
            NODE: 12345
I want the script to seach for the text string "NODE: " then assign a variable to "12345" for use later in the script....     objCmdOutput = "12345"

Thanks
0
Comment
Question by:geewizzz
  • 3
  • 3
6 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24148493
This should do for an example...
MyCommand = "C:\Folder\MyFile.exe"
 
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objExec : Set objExec = objShell.Exec (MyCommand)
 
Do While Not objExec.StdOut.AtEndOfStream
  strData = uCase(objExec.ReadLine)
  If Instr(strData, "NODE:") > 0 Then
    MyNode = Trim(Mid(strData, Instr(strData, ":") + 1))
    Exit Do
  End If
Loop

Open in new window

0
 

Author Closing Comment

by:geewizzz
ID: 31570468
Concise and accurate solution-- good stuff!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24151097
Glad I could help - thanx for the grade! :^)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:geewizzz
ID: 24156947
Actually, I used a peice of this and combined it with a script that first outputs to a text file.

I would like to see this one work still, issue is I get an error:  "object does not suuport method Readline"
You can confirm this yourself by using the 'ipconfig' command, then look for the "Win" string and capture everything from the "d" on...

Any thoughts?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24157023
Type-o, sorry...but if you look at the loop definition, you'll see how it should read...

Do While Not objExec.StdOut.AtEndOfStream

Here we're reading the standard output.  In the variable assignment, I neglected to include stdout, so that line should read:

  strData = uCase(objExec.StdOut.ReadLine)

Sorry about that...
0
 

Author Comment

by:geewizzz
ID: 24195368
Thanks again!!

I also have another question open on how to delete a locked file via a vbscript???
If your interested.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question