Solved

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

Posted on 2009-04-15
6
235 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

17 Experts available now in Live!

Get 1:1 Help Now