Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to invoke .bat file????

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,48849
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to invoke .bat file????
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to invoke .bat file???? - 6/28/2007 2:22:04 AM   
  naveen_mikki

 

Posts: 12
Score: 0
Joined: 6/28/2007
Status: offline
Hi I am new to VBScripting. Let me explain my scenario. We have a log file as shown below.
display variable 'LoadCubes'

Output columns prepared: [4]

Application Database Variable  Value
----------- -------- --------- -----
                     LoadCubes    ON

I would like to invoke a batch file based on the text value. That is if the value is "ON" run batch file. If value is "OFF". Do nothing.
How can i do that??
 
 
Post #: 1
 
 RE: How to invoke .bat file???? - 6/28/2007 2:58:11 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
Search this site for these terms:

WshShell
.Run

Or you could read the Frequently Asked Stuff thread http://www.visualbasicscript.com/m_47117/tm.htm

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to naveen_mikki)
 
 
Post #: 2
 
 RE: How to invoke .bat file???? - 6/28/2007 4:07:26 AM   
  naveen_mikki

 

Posts: 12
Score: 0
Joined: 6/28/2007
Status: offline
I dont have permission to search here!!!!

(in reply to naveen_mikki)
 
 
Post #: 3
 
 RE: How to invoke .bat file???? - 6/28/2007 4:13:06 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
You don't?? That is wierd. What happens when you click on the Search at the very Top Right of the page?


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to naveen_mikki)
 
 
Post #: 4
 
 RE: How to invoke .bat file???? - 6/28/2007 4:59:46 AM   
  naveen_mikki

 

Posts: 12
Score: 0
Joined: 6/28/2007
Status: offline
yes I did search. But i didn't find any information on reading text value and using conditional logic based on that text value. 

(in reply to naveen_mikki)
 
 
Post #: 5
 
 RE: How to invoke .bat file???? - 6/28/2007 5:06:04 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
Well if you just want to know how to implement conditional logic based on text, look at the WSH documentation for:

InStr
If - Then
Select - Case

Most of the examples are based on text.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to naveen_mikki)
 
 
Post #: 6
 
 RE: How to invoke .bat file???? - 6/28/2007 6:50:34 AM   
  naveen_mikki

 

Posts: 12
Score: 0
Joined: 6/28/2007
Status: offline
Still not doing good. My is as follows

Part1
Dim arrFileLines()
Dim WshShell
Dim oExec
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\New.txt", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Wscript.Echo arrFileLines(l)
Next

That part 1 is working we i think. It is displaying line by line array values from bottom to top


Part2

If arrFileLines(1)="LoadCubes     ON " Then

Set WshShell = wscript.createobject("Wscript.Shell")
Set oExec = WshShell.Run ("c:\Scripts\RUNIT.bat")

Else
  MsgBox "LoadCubes Value is set to OFF"
End If

In Part 2  i am getting LoadCubes Value is set to OFF... Even my first line of array shows LoadCubes  ON......

What could be the error. I new to this Scripting....I need all your Help..

Regards
Naveen

(in reply to naveen_mikki)
 
 
Post #: 7
 
 RE: How to invoke .bat file???? - 6/28/2007 7:32:11 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
First, if you need the contents of a file in an array you can do it like this:

Dim arrFileLines
Dim WshShell
Dim oExec

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\New.txt", 1)
arrFileLines = Split(objFile.ReadAll(), vbCrLf)
objFile.Close

For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Wscript.Echo arrFileLines(l)
Next

You need to remember that VBScript arrays start their numbering at 0. So the first line of the file is actaully arrFileLines(0). So try this:

If arrFileLines(0)="LoadCubes     ON " Then

Set WshShell = wscript.createobject("Wscript.Shell")
Set oExec = WshShell.Run ("c:\Scripts\RUNIT.bat")

Else
MsgBox "LoadCubes Value is set to OFF"
End If

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to naveen_mikki)
 
 
Post #: 8
 
 RE: How to invoke .bat file???? - 6/28/2007 8:05:50 AM   
  naveen_mikki

 

Posts: 12
Score: 0
Joined: 6/28/2007
Status: offline
No result.

My New.text file is shown below

display variable 'LoadCubes'

Output columns prepared: [4]

Application Database Variable  Value
----------- -------- --------- -----
                     LoadCubes    ON

and my VbScript to call batch file based on "LoadCubes     ON" string is show below

Dim arrFileLines
Dim WshShell
Dim oExec

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\New.txt", 1)
arrFileLines = Split(objFile.ReadAll(), vbCrLf)
objFile.Close

For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Wscript.Echo arrFileLines(l)
Next


If arrFileLines(0)="LoadCubes     ON " Then

Set WshShell = wscript.createobject("Wscript.Shell")
Set oExec = WshShell.Run ("c:\Scripts\RUNIT.bat")

Else
MsgBox "LoadCubes Value is set to OFF"
End If

It is not invoking batch file, Even if my valus is "LoadCubes     ON"

My result in the Msg box is
1st Box                                            (that is empty)
2nd Box LoadCubes   ON
3rd Box ----------- -------- --------- -----
4th Box Application Database Variable  Value
5th Box           
6th Box  Output columns prepared: [4]
7th Box
8th Box  display variable 'LoadCubes'      
9th Box LoadCubes Value is set to OFF

It is clearly showing LoadCubes  ON on 2nd Box. Then why is that .bat file in not invoking??This could be something wrong at If line. Because it is going to Else statement..
Is this is the right procedure to do it??

(in reply to naveen_mikki)
 
 
Post #: 9
 
 RE: How to invoke .bat file???? - 6/29/2007 12:59:50 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
When you go through and show the lines from the file you are doing it backwards. That is what the Step - 1 does. So the line that you are interestaed in is actually the 7th line in the file. When you put it in the array since the aray starts counting at 0, you are interested in index 6. So change this line:

If arrFileLines(0)="LoadCubes     ON " Then


To this:

If arrFileLines(6)="LoadCubes     ON " Then

Also, the tex line looks like it has some white space at the beginning (tabs or spaces) so it will never exactly equal "LoadCubes     ON " because you don't include the spaces in your test. That means that this line:

If arrFileLines(6)="LoadCubes     ON " Then

should be something like:

If arrFileLines(6)="                     LoadCubes    ON " Then 

So that the white space is part of the test.



_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to naveen_mikki)
 
 
Post #: 10
 
 RE: How to invoke .bat file???? - 7/1/2007 7:06:19 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
In the Part 2, set a wscript.echo "part2" so you know when its at least getting there,
I think your if statement or even case is wrong, I usually do

If Instr(strText, "load on") > 0 Then
wscript.echo "Got it"
end if

hum.. i am not 100% that this would work because Instr should be used withing a string not array,
but you can always do
array(i)=strText
do the if here.
anyways check more info in InStr http://www.w3schools.com/vbscript/func_instr.asp

Maybe the spaces of the array is a problem for the if statement?

cheers,

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to naveen_mikki)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to invoke .bat file???? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts