0
votes
SETLOCAL ENABLEDELAYEDEXPANSION
curl "http://example.net/?u=%VARIABLE%" >> TXT.txt
wscript "C:\THAT.vbs" 
start "" "http://url.com/%VARIABLE%"
exit

I have (above) batch file that runs CURL and writes output into a txt file. And this (below) vbs file reads the content and shows message. As you can see there is a start command in my batch file. If I click Yes in vbs window I want to execute that start command. If I click No in vbs window I want to go to exit.

Option Explicit
Const conForReading = 1
Dim objFSO, objReadFile, objFile, contents, result, shell, WshShell, somestring, txFldr2Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("TXT.txt") 

If objFile.Size > 0 Then 
Set objReadFile = objFSO.OpenTextFile("TXT.txt", 1, False)
contents = objReadFile.ReadAll
result = MsgBox ("HEADTEXT;" & vbCr & contents & "",vbYesNo+vbExclamation+vbSystemModal,"HEADQUESTION?")
Select Case result
Case vbYes
LET THE BATCH FILE KNOW ANSWER IS YES
Case vbNo
LET THE BATCH FILE KNOW ANSWER IS NO
End Select
objReadFile.close

Else 
End If  

Set objFSO = Nothing 
Set objReadFile = Nothing 
WScript.Quit() 

It it possible to do that? If so how?

1

1 Answers

0
votes

Use the exit code from vbscript to return the selection to batch script

batch file

SETLOCAL ENABLEDELAYEDEXPANSION
curl "http://example.net/?u=%VARIABLE%" >> TXT.txt
cscript //nologo "C:\THAT.vbs" 
if not errorlevel 1 (
    start "" "http://url.com/%VARIABLE%"
)
exit

that.vbs

Option Explicit
Const conForReading = 1
Dim objFSO, contents, result

    result = 1

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If objFSO.GetFile("TXT.txt").Size > 0 Then 

        contents = objFSO.OpenTextFile("TXT.txt", 1, False).ReadAll

        If MsgBox ("HEADTEXT;" & vbCr & contents & "",vbYesNo+vbExclamation+vbSystemModal,"HEADQUESTION?") = vbYes Then
            result = 0
        End If 

    End If  

    WScript.Quit result