
VBScript front-end to a console app.
Quote:
> I'm writing a VBScript front-end to a console app. How do I pass input into
> a program called from vbscript?
> Set WSHShell= WScript.CreateObject ("WScript.Shell")
> WSHShell.Run "%comspec%/ c program.exe", 0, True
> The program (program.exe) prompts for input through standard io:
> Program.exe>> Enter the name of the file to encode/decode
> I need to turn this into an input box
> Programs.exe>> Press esc to encode, return to decode
> I need to turn this into a message box with two buttons encode and
> decode
> How do I pass an esc char to the program through vbscript?
I am assuming we are talking about a stand alone WSH hosed script. If
so, request the info from the user BEFORE you issue the Run. You can
use the InputBox to request the name of the file to be processed:
sFilename = InputBox("File to be encoded/decoded")
For the second piece of input you have several choices:
1. Use the InputBox function again, or
2. Use a MsgBox with one of the Three button option constants to
provide two buttons and a cancel, again before issuing the Run. This is
an imperfect, but easy approach, since it will require explanation text
to have the buttons stand in for Encode/Decode. They cannot be
renamed. So, it would look something like this, say using the
vbYesNoCancel constant ...
title = "Make a selection"
prompt = "Press Yes to Encode or No to Decode"
buttons = vbYesNoCancel
Result = MsgBox(prompt, buttons, title)
Select Case Result
Case vbYes
Result = Chr(27) ' The escape character
Case vbNo
Result = Chr(13) ' The Carrage return character
Case vbCancel
Wscript.Quit
End Select
3. Or, the whole input process can be done in a 'console' with the
correctly labeled buttons and a file lookup feature using Michael
Harris' fine scripting component, Msg.wsc. This is the 'best looking'
solution, if you have IE 4 or 5 loaded on the machine(s). But, it does
require a good deal of programming. More than I want to attempt in
answer to this question. If you want to pursue it, the component is
available for free download at Clarence Washington's site:
http://cwashington.netreach.net/main_site/default.asp
Then, with the user input, you need to create a temporary input file for
use with your program. For example, ...
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oInF = oFS.OpenTextFile("C:\~tmp.txt", 2, True)
oInF.WriteLine sFilename
oInF.Write Result
oInf.Close
Finally, Run the program with its input, supplied via redirection ...
Set WSHShell= WScript.CreateObject ("WScript.Shell")
WSHShell.Run "%comspec%/ c program.exe < C:\~tmp.txt", 0, True
oInf.Delete
The last line deletes the temporary input file.
This needs to be cleaned up, and maybe configured to accept Drag and
Drop delivery of the file to the procedure through WSH's Arguments
property, but this gives you an idea of how to start.
Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/