how to use the result of a vbscript in the input of another vbscript

hello Expert ,

Can ‘I know please how I can use the output of a vbscript code for example (result of a calculi or result of a research) in another vbscript

thanks for your help
mell lian90Asked:
Who is Participating?
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.

Bill PrewCommented:
What form will the results take?  Are they always an integer number, or a decimal number, or a single string of data, etc?  Or could it be multiple lines of output?


»bp
0
mell lian90Author Commented:
hello Bill Prew ,
I have to kind of results the first vbsript   return a singale string and the second vbscript  return a decimal number
thanks for your help ..
0
Bill PrewCommented:
This should give you an approach.  Save these two files and then run the first one from a BAT or Command prompt as follows:

cscript //nologo EE29072773A.VBS

It will run the second script, which writes a value to STDOUT, and when it finishes, the first script display the value.


***** EE29072773A.VBS *****
' Constants for Wscript.Exec status
Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2

' Command line EXE to run
strCommand = "cscript //nologo EE29072773b.vbs"

' Execute the command
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)

' Wait for it to finish
Do While WshShellExec.Status = WshRunning
     WScript.Sleep 250
Loop

' Capture STDOUT or STDERR to variable
Select Case WshShellExec.Status
   Case WshFinished
       strOutput = WshShellExec.StdOut.ReadAll
   Case WshFailed
       strOutput = WshShellExec.StdErr.ReadAll
End Select

' Display on console for testing, could use in a write to a log
WScript.Echo strOutput

Open in new window

***** EE29072773B.VBS *****
Result = 12.34
WScript.Echo Result

Open in new window


»bp
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

mell lian90Author Commented:
ok , thanks you i will try it :)
thanks again
0
aikimarkCommented:
You write to StdOut in the first script and read from StdIn in the second script
0
mell lian90Author Commented:
hi aikimark ,

Could you please explain to me how i use StdIn in the second script?   and how my program can know that i use the output of the first program ?
thanks
0
Bill PrewCommented:
You already have a working example that I posted earlier, did that not work for you (it's the same approach mentioned by aikimark).


»bp
0
mell lian90Author Commented:
@ Bill Prew ;
thanks for your answer , but it  not working for me , it return nothing , maybe i need to redirect my result in a text file and then use your script..
0
Bill PrewCommented:
The example I gave did work.  I assume you have tried to adapt it to your code?  If so, then post the scripts you are running that aren't working so we can see them and make suggestions / corrections.


»bp
0
mell lian90Author Commented:
Ok , i just tried to take the output of my file and use directly your script file EE29072773A.VBS to show the result and isn't work ..
below you found the 2 script that i use without any modification,
the first script named Rate.vbs , this script need to take the value of Currencies from the second script named :Currency.vbs
Rate.vbs
Currency.vbs
0
Bill PrewCommented:
I think I would need to see your changed versions.  I don't see either of these scripts executing the other.


»bp
0
mell lian90Author Commented:
i don't need that one script execute the other ,i need that the second script use the result of the first script..
i hope that my need was clear for you  :)
0
Bill PrewCommented:
So if I understand correctly you have two scripts.  You want to run one script first, and have it output to a text file it's results.  Then, after it completes, you want to run a second script.  That second script needs to read the text file produced by the first script and act on it.  Is that correct?


»bp
0
mell lian90Author Commented:
yes exactly.. but i don't know if i need a text file to save my output result..
0
aikimarkCommented:
StdOut and StdIn are not file operations.
0
Bill PrewCommented:
If you want / need to run the two scripts independently of each other, then you will need a file on disk to save the results to and pass to the next script.

If you want / need to have the first script execute the second and get the results when it finishes then you would use the STDOUT / STDIN approach as I showed in my example above.

It's up to you which approach makes sense for you in your environment.


»bp
1
mell lian90Author Commented:
i need to execute the first script and then use her result as an input for the second script .. and then execute the second script ..
0
Bill PrewCommented:
This should give you the idea.  Save these two files and then run the first one and then the second from a BAT or Command prompt as follows:

cscript //nologo EE29072773A.VBS
cscript //nologo EE29072773B.VBS

***** EE29072773A.VBS *****
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
strOutFile = "c:\temp\out.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.OpenTextFile(strOutFile, ForWriting, True)
strResult = "12.34"
objOutFile.WriteLine strResult
objOutFile.Close

Open in new window

***** EE29072773B.VBS *****
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
strInFile = "c:\temp\out.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
Do Until objInFile.AtEndOfStream
    strLine = objInFile.ReadLine
    Wscript.Echo "Input line = " & strLine
Loop
objInFile.Close

Open in new window


»bp
0

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:
Are sure that EE29072773A.VBS work ?
0
Bill PrewCommented:
Yes, I tested them both here and they work.

As coded, the file that is created in A and read by B is located in "C:\Temp\out.txt", so the "C:\Temp" folder would have to exist.  This was just for example, you can change that location to anything you want.


»bp
0
mell lian90Author Commented:
yes , i know .. but it worked for me when i delete obj File.Close
and i don't know why.. and i tested it in my script and it work also ,
thanks for your help
0
mell lian90Author Commented:
the best solution ,it work perfectly for me
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.