Solved

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

Posted on 2009-04-15
6
246 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
[X]
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
  • 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
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!

 

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

Technology Partners: 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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.

732 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