How to run in order multiple .vbs scripts which requires an input file to run

hello Expert ,

I need to run in order multiple .vbscript which  requires an input file to run  , i found the below code
set WSshell = createobject("wscript.shell")
WSshell.run "C:\1.vbs"
WSshell.run "C:\2.vbs"
WSshell.run "C:\3.vbs"

but I don't know how to add the the input file source to run each code
thanks for your help
mell lian90Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
but I don't know how to add the the input file source to run each code

We neither, cause it depends on each invoked script, what "input file" means. It could be piped (std in),  per simple parameter or as complex parameter..

Set WSshell = CreateObject("wscript.shell")
WSshell.run "C:\1.vbs < input.txt"
WSshell.run "C:\2.vbs input.txt"
WSshell.run "C:\3.vbs -I input.txt"

Open in new window

mell lian90Author Commented:
@ste5an ,
 thanks for your answer , and if i want to run the script with order how can i proceed ?
ste5anSenior DeveloperCommented:
As I already wrote:  
it depends on each invoked script
I'm neither a mind reader nor a code oracle..
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

mell lian90Author Commented:
i use  WSshell.run "C:\2.vbs input.txt"   to run my script ...
Sorry but maybe i don't understand what you mean
Bill PrewIT / Software Engineering ConsultantCommented:
So, wouldn't you just do:

set WSshell = createobject("wscript.shell")
WSshell.run "C:\1.vbs input.txt"
WSshell.run "C:\2.vbs input.txt"
WSshell.run "C:\3.vbs input.txt"

Open in new window


»bp
ste5anSenior DeveloperCommented:
Exactly that, how should I have know that?

Do you mean invoking the parent script with a parameter and passing this to the child scripts?

Set WSShell = CreateObject("WScript.Shell")
WSShell.Run "C:\1.vbs " & WScript.Arguments.Item(0)
WSShell.Run "C:\2.vbs " & WScript.Arguments.Item(0)
WSShell.Run "C:\3.vbs " & WScript.Arguments.Item(0)

Open in new window

mell lian90Author Commented:
hello @ Bill Prew,
So i don't need to write this :

set WSshell = createobject("wscript.shell")
WSshell.run "C:\3.vbs input.txt"

at the and of "2.vbs"

to run all the script in order ?
Bill PrewIT / Software Engineering ConsultantCommented:
Based on your original question it looked like you had a "driver" VBS that was going to run each of the other three in sequence.  That's how it looked anyway, and is certainly an approach.

Another approach could certainly be to have each of the VBS script run the next in sequence, but it feels like that would be less clean than the driver approach.  Really depends on your circumstances.

And if you really need to always run all three together, then of course another approach is just to merge them into one large VBS.


»bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mell lian90Author Commented:
@Bill Prew
Thanks of this clarification, but after doing same test on my different script I found that for some script :
set WSshell = createobject("wscript.shell")
WSshell.run "C:\1.vbs input.txt"

Open in new window

Don’t work ..
I give you an example  :
I have a script that use  2 input file source .. , for the first input file I put the source path in my script , and I put the second input file using the Command Prompt window ..
In this case how can I proceed to run my script in a vbscript?
thanks
Bill PrewIT / Software Engineering ConsultantCommented:
for the first input file I put the source path in my script , and I put the second input file using the Command Prompt window ..
If you want to be able to change both of those file paths at runtime from the driver script then you would need to pass them on the command line, and change the called script to get the file paths from the command line (WScript.Arguments).


»bp
mell lian90Author Commented:
Sorry @ Bill Prew ,I don’t understand what you means..
if for example I have the below code , and I need to read a vbscript to run it how can I write my  input file ??
thanks
test.vbs
Bill PrewIT / Software Engineering ConsultantCommented:
I need to read a vbscript to run it how can I write my  input file
Apologies, I don't understand what you are saying in this statement...


»bp
mell lian90Author Commented:
sorry ..
if i  need to write a vbscript  to run my  previous code how can i do ?
thanks
Bill PrewIT / Software Engineering ConsultantCommented:
Set WSshell = CreateObject("wscript.shell")
WSshell.run "C:\test.vbs"

Open in new window

mell lian90Author Commented:
it's don't work  .. i have the message: no input file
and when i use
set WSshell = createobject("wscript.shell")
WSshell.run "C:\test.vbs input.txt"

Open in new window


i have not a result ... I have the impression that he does not read my input file
Bill PrewIT / Software Engineering ConsultantCommented:
This worked fine here, and is like your code in terms of getting the parm.  Are you sure you are passing a valid path to a file?

***** B:\EE\EE29073271\1.vbs *****
set WSshell = createobject("wscript.shell")
WSshell.run "B:\EE\EE29073271\2.vbs input.txt"

Open in new window


***** B:\EE\EE29073271\2.vbs *****
If (WScript.Arguments.Count > 0) Then
   strInFile = WScript.Arguments(0)
Else
   WScript.Echo "No input filename specified."
   WScript.Quit
End If

Wscript.Echo "strFileIn = " & strInFile

Open in new window


»bp
mell lian90Author Commented:
hello ,

yes i'm sure that i'm passing the valid path , but it didn't work ..
Bill PrewIT / Software Engineering ConsultantCommented:
You will have to debug a bit, place some Wscript.Echo statements in your code along the way showing where you are in the code and what certain variables contain.  That may help you track down your problem.

Other than that, I would need the exact scripts and data files you are testing with to try and debug here.


»bp
mell lian90Author Commented:
@Bill Prew ,
 I merge all the scripts into one large VBS script .. i found that's the perfect solution :)
thank's for your help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.