Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-15
6
Medium Priority
?
259 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

971 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