.NET Framework - How to Alert Confirm or Prompt in CScript JSctipt ?

Asked By Dr J R Stockton on 14-Nov-11 06:36 PM
In Web-page JavaScript/JScript, there are useful functions alert,
confirm, prompt.

How can I do something functionally similar in my SEEK.JS, which is
called by the batch line
@cscript //nologo SEEK.JS %1 ... %9
when working in a Command Prompt window?

The script is a partial emulation of HUNT, a 16-bit Pascal program,
which does confirm and prompt by writing a question line to the screen,
without a newline, and then reading a response line from the keyboard.
If possible, I'd like the same, otherwise similar.

The alert function might not be needed for the final code; but in
debugging it would be nice to have it pop up as a small window.

I am currently using WinXP sp3, but this is something that I want to work
in any Windows system I might get in future.

(c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  IE8 FF3 Op12 Sf5 Cr12

Michael Bednarek replied to Dr J R Stockton on 15-Nov-11 03:22 AM

Does this help: "Invoking an Input Dialog Box in JScript"?

Michael Bednarek                           "ONWARD"
Dr J R Stockton replied to Michael Bednarek on 16-Nov-11 05:57 PM
In microsoft.public.scripting.jscript message <j284c71bqch2o30h52g4vbfg8

It might.  I did not know about WSF 2.  I did, however, know about
mixing VBScript and JScript on Web pages for IE.

If a file that runs at a command prompt using the batch line
@cscript //nologo SEEK.JS %1 ... %9
can easily be changed to be a WSF 2 file that can be started from the
command line, and that mainly writes to the command prompt console, then
the answer is probably YES. .... BUT

P.S.    I added    WScript.echo(result)   to the end of the JavaScript
taken from the page you cited, and it appeared pop-up, not to
DOS box.  DOS box output is essential.

I'd much prefer the user to work only in the Command Prompt box.
But, looking at that page again, that is probably not possible.

If I remain with CScript and *.js, another question - can a *.js file
being run by WScript as GUI detect that WScript and abort, crash, or
convert to CScript?  A CScript run is fast; an inadvertent WScript run
can require far too many clicks.

P.P.S.  The aforesaid test, when run command-line using CScript, writes
to the DOS box where wanted; the condition of the P.S. is

If background is wanted, see
looking for SEEK.BAT.  However, I am in the middle of another, not
necessarily easy, functional addition to the script, and then the code
needing the response will have to be written, so I will not immediately
WSF it.

Meanwhile, here is something showing what confused me for a while :


DOSprompt>type $1.js
WScript.echo(NaN, NaN.toString(), NaN)          Simple enough

DOSprompt>cscript//nologo $1.js
1.#QNAN NaN 1.#QNAN                             Unexpected

Anyway, thanks for the answer, including the link; whether or not I can
use WSF 2 in this job, it is nice to know about.

(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike v6.05  MIME.
Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Evertjan. replied to Dr J R Stockton on 17-Nov-11 08:20 AM
Dr J R Stockton wrote on 16 nov 2011 in microsoft.public.scripting.jscript:

Use cscript in the command prompt and write to StdOut:


WScript.StdOut.Write('hello world');



C:\>cscript C:\test.js
Microsoft (R) Windows Script Host versie 5.8
Copyright (C) Microsoft Corporation 1996-2001. Alle rechten voorbehouden.

hello world


The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dr J R Stockton replied to Evertjan. on 18-Nov-11 05:35 PM
In microsoft.public.scripting.jscript message <Xns9FA05F1C7551Beejj99@19>, Thu, 17 Nov 2011 08:20:59, Evertjan. <exjxw.hannivoort@i
nterxnl.net> posted:

An alternative worth knowing about, certainly; differs from
WScript.echo, which I am using, in that it provides no newline.

WScript.StdIn.Read(St)  does not, it seems, read from the keyboard, as I
want to do.  I must read about it.

includes making typed one-letter responses.

Should that output use, instead, "Auteursrecht"?

Another general question, affecting what my code could or could not be
made to do directly :

In WSH or WSH 2, using .JS, .VBS, or .WSF, can script cause a string to
be executed as a MSDOS command line in the Command Prompt window that
the CScript is running in?  Or similar?

(c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  IE8 FF3 Op12 Sf5 Cr12
Dr J R Stockton replied to Dr J R Stockton on 19-Nov-11 03:07 PM
In microsoft.public.scripting.jscript message <I9w92WJ92txOFwZB@invalid.
uk.co.demon.merlyn.invalid>, Fri, 18 Nov 2011 22:35:41, Dr J R Stockton

This test shows what I needed & found to emulate HUNT, AFAICS :

if (1) { WScript.StdOut.Write("Asking? ")
Reply = WScript.StdIn.ReadLine()
WScript.echo("   Got", Reply) }

I need to know whether Read(0) should be called every time, or just

That is what I most want the above Reply to allow or decline.

(c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  DOS 3.3, 6.20; WinXP.
Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
PAS EXE TXT ZIP via  <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS  <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.