Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable to another script 2

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
I have scripts that needs to run right after each other. Is it possible to pass a variable from one script to another.
 
you can call a script with an argument. then in the script that is being called you access the
Wscript.Arguments collection and retrieve what was passed.
 
I'm quite new with VBScript, can you give me an example.
Say I have two script - Job1.vbs and Job2.vbs. I have a variable in Job1 called strMonth = "Aug" and I want to pass it to Job2, how do I pass it using WScript.Arguments?
 
In Job1.vbs:
Code:
Set oSh=CreateObject("WScript.Shell")
oSh.Run "cscript \Path\to\Job2.vbs " & strMonth
In Job2.vbs:
Code:
Set argv = WScript.Arguments
argMonth=argv(0)

Hope This Help
PH.
 
Thanks guys!

PVH, before I test it, I hust have a few more questions if you don't mind.

1. The Path to the 2nd script, can it be a relative path
2. If I need to pass some more variable, is this how I do
it:

Set oSh=CreateObject("WScript.Shell")
oSh.Run "cscript \Path\to\Job2.vbs " & strMonth & version
In Job2.vbs:
Set argv = WScript.Arguments
argMonth=argv(0)
argversion = argv(1)


 
1. If Job2 is in the same directory as Job1, try this:
Code:
Set oSh=CreateObject("WScript.Shell")
j2=Replace(WScript.ScriptFullName,"Job1","Job2")
oSh.Run "cscript " & j2 & " " & strMonth & " " & version
2. You can even test the number of command line parameters:
Code:
Set argv = WScript.Arguments
WScript.Echo argv.Count

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top