elwayisgod
asked on
Execute a .vbs file from another vbs file - not working
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
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
ASKER
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
splice-years.vbs
Here's an example of running a script from another:
Main
Second Script
Main
Set shell = WScript.CreateObject("WScript.Shell")
result = shell.Run("second_script.vbs",,True)
MsgBox(result)
Second Script
MsgBox "Yay!"
WScript.Quit(-1)
ASKER
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?
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.
Const C_FILELIST = "filelist.txt"
8 lines later
Set objFilelist = objFSO.OpenTextFile(C_FILE LIST, 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.
8 lines later
Set objFilelist = objFSO.OpenTextFile(C_FILE
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.
ASKER
Back tomorrow to try and resolve.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will try and give this a try today. Just slammed right now.
ASKER
OK. So right now attached is my 'splice_years.vbs' script. This script needs to reside in the 'D:\AppFiles\SDS\SDS_Retai l_R3\scrip ts' directory. The data files it needs to process against are in the 'D:\AppFiles\SDS\SDS_Retai l_R3\Data' directory. How can I edit this to make that work?
splice-years.vbs
splice-years.vbs
ASKER
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\Script s>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\Script s\splice_y ears.vbs(2 6, 2) Microsoft VBScript
runtime error: File not found
D:\AppFiles\SDS\SDS_Retail _R3\Script s>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\Script s\splice_y ears.vbs(2 6, 2) Microsoft VBScript
runtime error: File not found
D:\AppFiles\SDS\SDS_Retail
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
runtime error: File not found
D:\AppFiles\SDS\SDS_Retail
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
runtime error: File not found
ASKER
I'll post this as another question. Starting to creep into more issues.
ASKER
firs one worked perfectly. thanks. now if I can just get it to process data files from the data directory, I'm golden :)
ASKER
Now it's now working... I have no clue what is going on.
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.ScriptFull Name, 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.
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.ScriptFull
Which will set the data dir to the current directory the script is running from, no matter where you put it.
Regards,
Rob.
Similarly, when launching Splice_Years.vbs from the first script, if they're always in the same folder, instead of this:
you can use
Rob.
intErr = objShell.Run("cscript.exe ""D:\AppFiles\SDS\SDS_Retail_R3\Scripts\splice_years.vbs""", 0, False)
you can use
intErr = objShell.Run("cscript.exe """ & Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "splice_years.vbs""", 0, False)
Rob.
ASKER
D:\AppFiles\SDS\SDS_Retail
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
runtime error: File not found
D:\AppFiles\SDS\SDS_Retail