Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Alert Confirm or Prompt in CScript JSctipt ?

1,220 views
Skip to first unread message

Dr J R Stockton

unread,
Nov 14, 2011, 6:36:48 PM11/14/11
to
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'm 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
news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
<http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Michael Bednarek

unread,
Nov 15, 2011, 3:22:03 AM11/15/11
to
On Mon, 14 Nov 2011 23:36:48 +0000, Dr J R Stockton wrote in
microsoft.public.scripting.jscript:

>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'm currently using WinXP sp3, but this is something that I want to work
>in any Windows system I might get in future.

Does this help: "Invoking an Input Dialog Box in JScript"?
http://wsh2.uw.hu/ch08c.html

--
Michael Bednarek "ONWARD"

Dr J R Stockton

unread,
Nov 16, 2011, 5:57:52 PM11/16/11
to
In microsoft.public.scripting.jscript message <j284c71bqch2o30h52g4vbfg8
qbb3...@4ax.com>, Tue, 15 Nov 2011 18:22:03, Michael Bednarek
<mbATmbed...@BLACKHOLESPAM.NET> posted:
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's 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
satisfied.


If background is wanted, see
<http://www.merlyn.demon.co.uk/programs/32-bit/00index.htm> (short),
looking for SEEK.BAT. However, I'm 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's something showing what confused me for a while :


PARTIAL COMMAND-PROMPT SCREEN-COPY COMMENT

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's 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.

unread,
Nov 17, 2011, 3:20:59 AM11/17/11
to
Dr J R Stockton wrote on 16 nov 2011 in microsoft.public.scripting.jscript:

> 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's probably not possible.

Use cscript in the command prompt and write to StdOut:

test.js:
===========================

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

==========================

result:
==========================

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

hello world
C:\>

=========================



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Dr J R Stockton

unread,
Nov 18, 2011, 5:35:41 PM11/18/11
to
In microsoft.public.scripting.jscript message <Xns9FA05F1C7551Beejj99@19
4.109.133.133>, 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.

"I'd much prefer the user to work only in the Command Prompt box"
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?

--

Dr J R Stockton

unread,
Nov 19, 2011, 3:07:13 PM11/19/11
to
In microsoft.public.scripting.jscript message <I9w92WJ92txOFwZB@invalid.
uk.co.demon.merlyn.invalid>, Fri, 18 Nov 2011 22:35:41, Dr J R Stockton
<repl...@merlyn.demon.co.uk> posted:


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

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

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


># # # # #
>
>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?

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.
0 new messages