![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Return value from VBScript to cmd file I'm modifying a Windows command script that needs to use a value from the Win32_OperatingSystem class. How can I call a VBScript from inside the cmd script and return a value to the cmd script? Brian Bygland |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Return value from VBScript to cmd file "BrianB" <brian@xxxxxx> wrote in message news:%23w0kMEVRJHA.4916@xxxxxx Quote: > I'm modifying a Windows command script that needs to use a value from the > Win32_OperatingSystem class. How can I call a VBScript from inside the cmd > script and return a value to the cmd script? > > Brian Bygland @echo off {Your code} cscript //nologo c:\Scripts\YourScript.vbs echo Return code = %ErrorLevel% {More of your own code} Your VB Script could terminate like so: wscript.quite 9 |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Return value from VBScript to cmd file On Nov 13, 1:58*am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > "BrianB" <br...@xxxxxx> wrote in message > > news:%23w0kMEVRJHA.4916@xxxxxx > Quote: > > I'm modifying a Windows command script that needs to use a value from the > > Win32_OperatingSystem class. How can I call a VBScript from inside the cmd > > script and return a value to the cmd script? Quote: > > Brian Bygland > Your command script (=batch file) could look like so > @echo off > {Your code} > cscript //nologo c:\Scripts\YourScript.vbs > echo Return code = %ErrorLevel% > {More of your own code} > > Your VB Script could terminate like so: > wscript.quite 9 read ... wscript.quit 9 While I'm here let me note that this approach can use a variable, as well, but that it can only return an integer between 0 and 255 to a batch procedure. For example, ... nNumber = 2 + 2 wscript.quit nNumber If the result is/can be larger than 255, is real or a string then try something like this instead ... in script: Result = 123.456 ' for exaple wscript.echo Result then in batch ... @echo off :: {Your code} for /f "delims=" %%a in ('cscript //nologo c:\Scripts \YourScript.vbs') do ( set ScriptOut=%%a) echo Script Result = %ScriptOut% Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Return value from VBScript to cmd file "Tom Lavedas" <tglbatch@xxxxxx> wrote in message news:dced8ce7-e6ed-42bb-8758-945639141cac@xxxxxx On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > "BrianB" <br...@xxxxxx> wrote in message > > news:%23w0kMEVRJHA.4916@xxxxxx > Quote: > > I'm modifying a Windows command script that needs to use a value from > > the > > Win32_OperatingSystem class. How can I call a VBScript from inside the > > cmd > > script and return a value to the cmd script? Quote: > > Brian Bygland > Your command script (=batch file) could look like so > @echo off > {Your code} > cscript //nologo c:\Scripts\YourScript.vbs > echo Return code = %ErrorLevel% > {More of your own code} > > Your VB Script could terminate like so: > wscript.quite 9 read ... wscript.quit 9 ============ "Quite" so! |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Return value from VBScript to cmd file Thank you all. Your suggestions will save my day Brian "Pegasus (MVP)" <I.can@xxxxxx> wrote in message news:OH$tYtZRJHA.3516@xxxxxx Quote: > > "Tom Lavedas" <tglbatch@xxxxxx> wrote in message > news:dced8ce7-e6ed-42bb-8758-945639141cac@xxxxxx > On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: >> "BrianB" <br...@xxxxxx> wrote in message >> >> news:%23w0kMEVRJHA.4916@xxxxxx >> Quote: >> > I'm modifying a Windows command script that needs to use a value from >> > the >> > Win32_OperatingSystem class. How can I call a VBScript from inside the >> > cmd >> > script and return a value to the cmd script? Quote: >> > Brian Bygland >> Your command script (=batch file) could look like so >> @echo off >> {Your code} >> cscript //nologo c:\Scripts\YourScript.vbs >> echo Return code = %ErrorLevel% >> {More of your own code} >> >> Your VB Script could terminate like so: >> wscript.quite 9 > Typo in the last line (one that I'm prone to also). It should > read ... > > wscript.quit 9 > > ============ > > "Quite" so! > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Return value from VBScript to cmd file Have you considered setting an environment variable in your script to the value (string) that you want returned? "BrianB" <brian@xxxxxx> wrote in message news:uam%23wWbRJHA.3628@xxxxxx Quote: > Thank you all. Your suggestions will save my day > > Brian > > "Pegasus (MVP)" <I.can@xxxxxx> wrote in message > news:OH$tYtZRJHA.3516@xxxxxx Quote: >> >> "Tom Lavedas" <tglbatch@xxxxxx> wrote in message >> news:dced8ce7-e6ed-42bb-8758-945639141cac@xxxxxx >> On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: >>> "BrianB" <br...@xxxxxx> wrote in message >>> >>> news:%23w0kMEVRJHA.4916@xxxxxx >>> >>> > I'm modifying a Windows command script that needs to use a value from >>> > the >>> > Win32_OperatingSystem class. How can I call a VBScript from inside the >>> > cmd >>> > script and return a value to the cmd script? >>> >>> > Brian Bygland >>> >>> Your command script (=batch file) could look like so >>> @echo off >>> {Your code} >>> cscript //nologo c:\Scripts\YourScript.vbs >>> echo Return code = %ErrorLevel% >>> {More of your own code} >>> >>> Your VB Script could terminate like so: >>> wscript.quite 9 >> Typo in the last line (one that I'm prone to also). It should >> read ... >> >> wscript.quit 9 >> >> ============ >> >> "Quite" so! >> > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Return value from VBScript to cmd file "Jim de Graff" <rjdegraff@xxxxxx> wrote in message news:eIDF7lbRJHA.1448@xxxxxx Quote: > Have you considered setting an environment variable in your script to the > value (string) that you want returned? is available to the calling program? |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Return value from VBScript to cmd file "Pegasus (MVP)" <I.can@xxxxxx> wrote in message news:eJn2ZsbRJHA.4608@xxxxxx Quote: > > "Jim de Graff" <rjdegraff@xxxxxx> wrote in message > news:eIDF7lbRJHA.1448@xxxxxx Quote: >> Have you considered setting an environment variable in your script to the >> value (string) that you want returned? > How exactly would you set an environmental variable in a script so that it > is available to the calling program? Brian |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Return value from VBScript to cmd file >"Tom Lavedas" <tglbatch@xxxxxx> wrote in message Quote: >news:dced8ce7-e6ed-42bb-8758->945639141cac@xxxxxx >On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: >> "BrianB" <br...@xxxxxx> wrote in message >> >> news:%23w0kMEVRJHA.4916@xxxxxx >> Quote: >> > I'm modifying a Windows command script that needs to use a value from >> > the >> > Win32_OperatingSystem class. How can I call a VBScript from inside the >> > cmd >> > script and return a value to the cmd script? Quote: >> > Brian Bygland Quote: >If the result is/can be larger than 255, is real or a string then try >something like this instead ... > >in script: > > Result = 123.456 ' for exaple > wscript.echo Result > >then in batch ... > > @echo off >:: {Your code} > for /f "delims=" %%a in ('cscript //nologo c:\Scripts >\YourScript.vbs') do ( > set ScriptOut=%%a) > echo Script Result = %ScriptOut% > >Tom Lavedas example only catches the last line. How do I get it to capture the entire output. I tried: Set ScriptOut= for /f "delims=" %%Z in ('cscript //nologo c:\cc_trigs\jvbsout.vbs') do ( Set BVBTemp=%%Z Set ScriptOut=%ScriptOut%%BVBTemp% ) echo Script output: %BVBTemp% But this still just saves the last line. Brian |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Return value from VBScript to cmd file On Nov 13, 1:42*pm, "BrianB" <br...@xxxxxx> wrote: Quote: > "Pegasus (MVP)" <I....@xxxxxx> wrote in message > > news:eJn2ZsbRJHA.4608@xxxxxx > Quote: > > "Jim de Graff" <rjdegr...@xxxxxx> wrote in message > >news:eIDF7lbRJHA.1448@xxxxxx Quote: > >> Have you considered setting an environment variable in your script to the > >> value (string) that you want returned? Quote: > > How exactly would you set an environmental variable in a script so thatit > > is available to the calling program? > That would be a much more elegant solution if it is possible. > > Brian its 'elegance' because of the 'hacks' needed to make it happen. The reason it's not possible (within reason) is that a 'child' process gets a *temporary COPY* of the environment. A script can modify this COPY, but since it is temporary, it is NOT available to the calling process once the script ends. Access to the non-volatile version of the environment requires access to the Windows API, which cannot be done easily in script. A supporting application could be called, but all in all it seems much messier to me than the use of the FOR statement. Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Return Value From VBScript In .NET | .NET General | |||
| Return Powershell Error to VBscript | PowerShell | |||
| File Deletion - Gone but Return! | Vista General | |||
| return only certain lines from large text file | PowerShell | |||