Solved

Execute a .vbs file from another vbs file - not working

Posted on 2012-12-27
16
509 Views
Last Modified: 2013-01-07
I have a .vbs script that works fine when I run it from command prompt.  However I need to execute it from within another 'Master' vbs file.  I needs the false parameter as it doesn't need to wait...

Attached is the Master.vbs file

Line 253 is where it all starts... I just need the 'splice_years.vbs' script to run....
master.vbs
0
Comment
Question by:elwayisgod
  • 10
  • 3
  • 2
  • +1
16 Comments
 

Author Comment

by:elwayisgod
ID: 38725116
Well maybe something is wrong.  I try and fire it up via 'cscript splice_years.vbs' and get:


D:\AppFiles\SDS\SDS_Retail_R3\Scripts>cscript splice_years.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

start - 12/27/2012 12:47:00 PM
file actfisc.txt - 12/27/2012 12:47:00 PM
D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs(26, 2) Microsoft VBScript
 runtime error: File not found


D:\AppFiles\SDS\SDS_Retail_R3\Scripts>
0
 

Author Comment

by:elwayisgod
ID: 38725123
Here's the vbs file i want to execute.  No idea why it won't in this directory.  in my test directory it runs fine...
splice-years.vbs
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 38725127
Here's an example of running a script from another:

Main
Set shell = WScript.CreateObject("WScript.Shell")

result = shell.Run("second_script.vbs",,True)

MsgBox(result)

Open in new window


Second Script
MsgBox "Yay!"

WScript.Quit(-1)

Open in new window

0
 

Author Comment

by:elwayisgod
ID: 38725153
So the 'splice_years.vbs' must be in the data directory for it to run.  Why can't it be in the scripts directory?   Isn't it pointing to the data directory in the script to let it know where the data files that need spliced up reside?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 38725170
It shouldn't need to be in the same directory. I just had my example set up that way. Just make sure you properly point to the target file, either with an absolute path (as you seem to be doing) or with a correct relative path.
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38725367
Const C_FILELIST = "filelist.txt"

8 lines later

Set objFilelist = objFSO.OpenTextFile(C_FILELIST, 1, False)


If  "filelist.txt" does not exist in the folder where you are running Master.VBS you are going to have to specify the full path and file name.
0
 

Author Comment

by:elwayisgod
ID: 38730885
Back tomorrow to try and resolve.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 38738944
I would have thought this line should definately work:
intErr = objShell.Run("cscript.exe ""D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs""", 0, False)

Open in new window


But, if that really doesn't work for some odd reason, try this.

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
objShell.Run "cscript " & objFSO.GetFile("D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs").ShortPath, 1, False

Open in new window


Regards,

Rob,
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:elwayisgod
ID: 38741078
I will try and give this a try today.  Just slammed right now.
0
 

Author Comment

by:elwayisgod
ID: 38752123
OK.  So right now attached is my 'splice_years.vbs' script.  This script needs to reside in the 'D:\AppFiles\SDS\SDS_Retail_R3\scripts' directory.  The data files it needs to process against are in the 'D:\AppFiles\SDS\SDS_Retail_R3\Data' directory. How can I edit this to make that work?
splice-years.vbs
0
 

Author Comment

by:elwayisgod
ID: 38752192
OK.  When I launch the 'splice_years.vbs' form the command prompt in the 'scripts' direcotry, I get the below error.  I had to copy the 'actfisc.txt' file into the 'scripts' directory from the 'data' directory.  It processed the 'actfisc.txt' file ok, but when it tried the next file it errored out.  Why can't it look in the 'data' directory for the data files?


D:\AppFiles\SDS\SDS_Retail_R3\Scripts>cscript splice_years.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

start - 1/7/2013 11:25:52 AM
file actfisc.txt - 1/7/2013 11:25:52 AM
D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs(26, 2) Microsoft VBScript
 runtime error: File not found


D:\AppFiles\SDS\SDS_Retail_R3\Scripts>cscript splice_years.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

start - 1/7/2013 11:26:31 AM
file actfisc.txt - 1/7/2013 11:26:31 AM
file actppln.txt - 1/7/2013 11:26:55 AM
D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs(26, 2) Microsoft VBScript
 runtime error: File not found
0
 

Author Comment

by:elwayisgod
ID: 38752240
I'll post this as another question.  Starting to creep into more issues.
0
 

Author Closing Comment

by:elwayisgod
ID: 38752273
firs one worked perfectly.  thanks.  now if I can just get it to process data files from the data directory, I'm golden :)
0
 

Author Comment

by:elwayisgod
ID: 38752559
Now it's now working... I have no clue what is going on.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 38752912
Hi, I just took a look at your Splice_Years.vbs, and noticed the first line is this:
Const C_DATA_DIR = ".\"

This is going to cause problems, since the .\ relies on the "Working directory" of the script engine at the time, hence sometimes it will work, and sometimes not.  If the script is in the same Data folder all the time, try this:
Const C_DATA_DIR = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

Which will set the data dir to the current directory the script is running from, no matter where you put it.

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 38752981
Similarly, when launching Splice_Years.vbs from the first script, if they're always in the same folder, instead of this:
intErr = objShell.Run("cscript.exe ""D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs""", 0, False)

Open in new window


you can use
intErr = objShell.Run("cscript.exe """ & Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "splice_years.vbs""", 0, False)

Open in new window


Rob.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

16 Experts available now in Live!

Get 1:1 Help Now