Solved

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

Posted on 2009-04-15
6
232 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now