Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35521 > unrolled thread
| Started by | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| First post | 2018-08-18 12:46 -0700 |
| Last post | 2018-08-20 03:22 -0700 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.lang.javascript
Batch pipe JScript question Dr J R Stockton <J.R.Stockton@physics.org> - 2018-08-18 12:46 -0700
Re: Batch pipe JScript question "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-08-18 13:44 -0700
Re: Batch pipe JScript question Dr J R Stockton <J.R.Stockton@physics.org> - 2018-08-18 14:43 -0700
Re: Batch pipe JScript question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-18 23:07 +0200
Re: Batch pipe JScript question Dr J R Stockton <J.R.Stockton@physics.org> - 2018-08-18 15:09 -0700
Re: Batch pipe JScript question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-19 11:40 +0200
Re: Batch pipe JScript question Dr J R Stockton <J.R.Stockton@physics.org> - 2018-08-19 09:12 -0700
Re: Batch pipe JScript question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-19 22:49 +0200
Re: Batch pipe JScript question Dr J R Stockton <J.R.Stockton@physics.org> - 2018-08-20 03:22 -0700
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-08-18 12:46 -0700 |
| Subject | Batch pipe JScript question |
| Message-ID | <f15ab55b-562a-4005-a351-230861244b24@googlegroups.com> |
The following XXX.BAT is to be run at the CMD.EXE command line in
my Windows 7 & 10. It calls the XXX.JS and they work. Windows is
set to ISO8601 date/time, of course.
At present it is non-beneficial because I have yet to finish
composing the arguments of .replace - that should be no problem.
But it calls for reading the entire output of the DIR into
an array, and I would prefer to read in line-by-line (I know I
could .split the array at newlines).
Anyone know exactly how? probably along the lines of
while (EOF) do {
Read line
Process line
Write line
}
// XXX.BAT :
DIR Y*.* | CSCRIPT \UTYS\XXX.JS
// XXX.JS :
var tmp = WScript.StdIn.ReadAll()
var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, "$1 zzz ")
WScript.Echo(TEMP)
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2018-08-18 13:44 -0700 |
| Message-ID | <9f931518-5049-46a7-bacb-07922db8bb5e@googlegroups.com> |
| In reply to | #35521 |
On Saturday, August 18, 2018 at 2:46:11 PM UTC-5, Dr J R Stockton wrote:
> The following XXX.BAT is to be run at the CMD.EXE command line in
> my Windows 7 & 10. It calls the XXX.JS and they work. Windows is
> set to ISO8601 date/time, of course.
>
> At present it is non-beneficial because I have yet to finish
> composing the arguments of .replace - that should be no problem.
>
> But it calls for reading the entire output of the DIR into
> an array, and I would prefer to read in line-by-line (I know I
> could .split the array at newlines).
>
> Anyone know exactly how? probably along the lines of
> while (EOF) do {
> Read line
> Process line
> Write line
> }
>
>
> // XXX.BAT :
>
> DIR Y*.* | CSCRIPT \UTYS\XXX.JS
>
>
> // XXX.JS :
>
> var tmp = WScript.StdIn.ReadAll()
>
> var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, "$1 zzz ")
>
> WScript.Echo(TEMP)
Is there a reason why you can't use JScript completely here? There would be no need to parse.
<script>
var fso = new ActiveXObject("Scripting.FileSystemObject");
var enumFiles = new Enumerator(fso.GetFolder('.').Files)
for(;!enumFiles.atEnd(); enumFiles.moveNext()) {
var file = enumFiles.item()
WScript.Echo('Name: ' + file.Name + ' Path:' + file.Path)
}
</script>
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-08-18 14:43 -0700 |
| Message-ID | <50098592-32be-4410-aa28-9beaad3fd184@googlegroups.com> |
| In reply to | #35522 |
On Saturday, August 18, 2018 at 9:44:55 PM UTC+1, Michael Haufe (TNO) wrote:
> On Saturday, August 18, 2018 at 2:46:11 PM UTC-5, Dr J R Stockton wrote:
> > The following XXX.BAT is to be run at the CMD.EXE command line in
> > my Windows 7 & 10. It calls the XXX.JS and they work. Windows is
> > set to ISO8601 date/time, of course.
> >
> > At present it is non-beneficial because I have yet to finish
> > composing the arguments of .replace - that should be no problem.
> >
> > But it calls for reading the entire output of the DIR into
> > an array, and I would prefer to read in line-by-line (I know I
> > could .split the array at newlines).
> >
> > Anyone know exactly how? probably along the lines of
> > while (EOF) do {
> > Read line
> > Process line
> > Write line
> > }
> >
> >
> > // XXX.BAT :
> >
> > DIR Y*.* | CSCRIPT \UTYS\XXX.JS
> >
> >
> > // XXX.JS :
> >
> > var tmp = WScript.StdIn.ReadAll()
> >
> > var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, "$1 zzz ")
> >
> > WScript.Echo(TEMP)
>
>
> Is there a reason why you can't use JScript completely here? There would be no need to parse.
>
> <script>
> var fso = new ActiveXObject("Scripting.FileSystemObject");
> var enumFiles = new Enumerator(fso.GetFolder('.').Files)
>
> for(;!enumFiles.atEnd(); enumFiles.moveNext()) {
> var file = enumFiles.item()
> WScript.Echo('Name: ' + file.Name + ' Path:' + file.Path)
> }
> </script>
That's something like the core of SEEK, which you helped me with before.
I could (almost) certainly modify SEEK to add what I want to add
- provided that I can find a spare letter to invoke the option.
But modifying SEEK and its documentation would not be quick.
As is, though, I have the versatility of DIR on tap.
I now have the RegExp etc. working, and only want line-by-line
as that seems the proper way.
I see another reply in the thread ...
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2018-08-18 23:07 +0200 |
| Message-ID | <XnsA942EB3CBFE8Eeejj99@194.109.6.166> |
| In reply to | #35521 |
Dr J R Stockton <J.R.Stockton@physics.org> wrote on 18 Aug 2018 in
comp.lang.javascript:
> The following XXX.BAT is to be run at the CMD.EXE command line in
> my Windows 7 & 10. It calls the XXX.JS and they work. Windows is
> set to ISO8601 date/time, of course.
>
> At present it is non-beneficial because I have yet to finish
> composing the arguments of .replace - that should be no problem.
>
> But it calls for reading the entire output of the DIR into
> an array, and I would prefer to read in line-by-line (I know I
> could .split the array at newlines).
>
> Anyone know exactly how? probably along the lines of
> while (EOF) do {
> Read line
> Process line
> Write line
> }
>
>
> // XXX.BAT :
>
> DIR Y*.* | CSCRIPT \UTYS\XXX.JS
>
>
> // XXX.JS :
>
> var tmp = WScript.StdIn.ReadAll()
>
> var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, "$1 zzz ")
>
> WScript.Echo(TEMP)
What about this, John?
====== xxx.bat =========
@echo off
dir x*.* | cscript xxx.js
========================
====== xxx.js =========
var stdin = WScript.StdIn;
var stdout = WScript.StdOut;
var str;
while (!stdin.AtEndOfStream) {
str = stdin.ReadLine();
str = str.replace(/xxx/,'aaa');
stdout.WriteLine(str);
};
========================
I run a powershell window,
so first enter the 'cmd' command
to have it run bat-files there:
=== runtime output in PS window =====
PS D:\testhtml> cmd
Microsoft Windows [Version 10.0.17134.228]
(c) 2018 Microsoft Corporation. All rights reserved.
D:\testhtml>xxx.bat
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Volume in drive D is Data
Volume Serial Number is 9C00-9B98
Directory of D:\testhtml
18-08-2018 23:04 36 aaa.bat
18-08-2018 22:53 201 aaa.js
2 File(s) 237 bytes
0 Dir(s) 1,828,861,349,888 bytes free
D:\testhtml>
==================================
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-08-18 15:09 -0700 |
| Message-ID | <1effe412-1e7a-4140-a805-e24e05281ca2@googlegroups.com> |
| In reply to | #35523 |
On Saturday, August 18, 2018 at 10:10:15 PM UTC+1, Evertjan. wrote:
> Dr J R Stockton wrote on 18 Aug 2018 in
> comp.lang.javascript:
>
> > The following XXX.BAT is to be run at the CMD.EXE command line in
> > my Windows 7 & 10. It calls the XXX.JS and they work. Windows is
> > set to ISO8601 date/time, of course.
> > ...
> What about this, John?
>
> ====== xxx.bat =========
> @echo off
> dir x*.* | cscript xxx.js
> ========================
>
> ====== xxx.js =========
> var stdin = WScript.StdIn;
> var stdout = WScript.StdOut;
> var str;
>
> while (!stdin.AtEndOfStream) {
> str = stdin.ReadLine();
> str = str.replace(/xxx/,'aaa');
> stdout.WriteLine(str);
> };
> ========================
That looks just what I want, but it's too late to install
and test it tonight.
Meanwhile, though, I have :
============
:: PLUS-DOW.BAT JRS 2018-08-18+
DIR %* | CSCRIPT \UTYS\PLUS-DOW.JS
:: END
============
// PLUS-DOW.JS Add day-of-week to output of DIR, piped
// (c) JRS 2018-08-18+
// E.G. DIR %0 | CSCRIPT \UTYS\PLUS-DOW.JS
function AddDow(match) { return match + " " +
new Date(match.replace(/-/g, "/")).toString().substring(0, 3) }
var tmp = WScript.StdIn.ReadAll()
var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, AddDow)
WScript.Echo(TEMP)
WScript.Echo("Done")
WScript.Echo("\n")
// End
============
Your way might be better for piping the output into,
for example, FIND or MiniTrue.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2018-08-19 11:40 +0200 |
| Message-ID | <XnsA94376AFE4063eejj99@194.109.6.166> |
| In reply to | #35525 |
Dr J R Stockton <J.R.Stockton@physics.org> wrote on 19 Aug 2018 in comp.lang.javascript: > Your way might be better for piping the output into, > for example, FIND or MiniTrue. Yes, stdin and stdout are marvelous to bag piping. A pity jscript is not keeping up with javascript, else, for instance: ================ 'use strict'; const stdin = WScript.StdIn; const stdout = WScript.StdOut; const rep = (s) => s.replace(/xxx/,'aaa'); while (!stdin.AtEndOfStream) stdout.WriteLine(rep(stdin.ReadLine())); ================ [sorry, can't test that] -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-08-19 09:12 -0700 |
| Message-ID | <b6a9a974-1a69-4313-98ee-c6d984e45ef4@googlegroups.com> |
| In reply to | #35526 |
On Sunday, August 19, 2018 at 10:40:08 AM UTC+1, Evertjan. wrote:
> Dr J R Stockton wrote on 19 Aug 2018 in
> comp.lang.javascript:
>
> > Your way might be better for piping the output into,
> > for example, FIND or MiniTrue.
>
> Yes, stdin and stdout are marvelous to bag piping.
==========
N.B. No normal English person would ever say or write that;
to many English, Royalty excepted (they seem to like it),
"bagpiping" refers to something like vehement caterwauling.
It has been said that a WWII troopship, carrying a Scots regiment
across some part of the Indian Ocean, was reduced to a sinking condition
by an enemy torpedo. The resourceful Pipe Sergeant-Major firstly employed
his set of bagpipes to hearten the troops assembled on deck, secondly
used the bag of the disassembled set to help him float ashore, and
thirdly found the reassembled and dried set useful to dispel the
thereby-terrified local tigers.
> A pity jscript is not keeping up with javascript, ...
Maybe, but I prefer to use only code that I can read,
which means ECMA <= 3. And I take advantage of the
different format of Date.toString, unlikely to change.
The results of forgetting to remove the 'g' property
from the RegExp were somewhat surprising. But now :
// PLUS-DOW.JS Add day-of-week to output of DIR, piped I/O
// (c) JRS 2018-08-19+
// PLUS-DOW.BAT holds :
// @DIR %* /o:d | CSCRIPT //nologo C:\UTYS\PLUS-DOW.JS
function AddDow(match) { return match + " " +
new Date(match.replace(/-/g, "/")).toString().substring(0, 3) }
//// OK, not preferred
//// var tmp = WScript.StdIn.ReadAll()
//// var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, AddDow) // g HERE ONLY
//// WScript.Echo(TEMP)
var stdin = WScript.StdIn
var stdout = WScript.StdOut
var str, RE = /(\d\d\d\d.+:\d\d )/
while (!stdin.AtEndOfStream) {
str = stdin.ReadLine()
if (RE.test(str)) {
str = str.replace(RE, AddDow)
stdout.WriteLine(" " + str) } }
// End
Sample output :
2014-01-10 14:29 Fri 1,165,170 $CURRASH.PNG
2014-03-05 00:48 Wed 3,058 SHIUMING.TXT
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2018-08-19 22:49 +0200 |
| Message-ID | <XnsA943E833B7EDFeejj99@194.109.6.166> |
| In reply to | #35527 |
Dr J R Stockton <J.R.Stockton@physics.org> wrote on 19 Aug 2018 in
comp.lang.javascript:
> On Sunday, August 19, 2018 at 10:40:08 AM UTC+1, Evertjan. wrote:
>> Dr J R Stockton wrote on 19 Aug 2018 in
>> comp.lang.javascript:
>>
>> > Your way might be better for piping the output into,
>> > for example, FIND or MiniTrue.
>>
>> Yes, stdin and stdout are marvelous to bag piping.
> ==========
> N.B. No normal English person would ever say or write that;
I've never met a normal English person,
and probably would hate it when I would.
Normality is not something to strive for,
and a dirthy mind should be a joy forever.
> to many English,
I prefer the Scottish version.
> Royalty excepted (they seem to like it),
> "bagpiping"
I dit not write that.
> refers to something like vehement caterwauling.
>
> It has been said that a WWII troopship, carrying a Scots regiment
> across some part of the Indian Ocean, was reduced to a sinking condition
> by an enemy torpedo. The resourceful Pipe Sergeant-Major firstly employed
> his set of bagpipes to hearten the troops assembled on deck, secondly
> used the bag of the disassembled set to help him float ashore, and
> thirdly found the reassembled and dried set useful to dispel the
> thereby-terrified local tigers.
>
>
>> A pity jscript is not keeping up with javascript, ...
>
> Maybe, but I prefer to use only code that I can read,
> which means ECMA <= 3. And I take advantage of the
> different format of Date.toString, unlikely to change.
>
> The results of forgetting to remove the 'g' property
> from the RegExp were somewhat surprising. But now :
>
>
> // PLUS-DOW.JS Add day-of-week to output of DIR, piped I/O
> // (c) JRS 2018-08-19+
> // PLUS-DOW.BAT holds :
> // @DIR %* /o:d | CSCRIPT //nologo C:\UTYS\PLUS-DOW.JS
>
> function AddDow(match) { return match + " " +
> new Date(match.replace(/-/g, "/")).toString().substring(0, 3) }
I would think there is no use for the replace function here.
However, I love Regex to much to go without, so:
function AddDow(match) {
return match +
" " +
new Date(match).toString().replace(/ .*/,'');
};
> //// OK, not preferred
> //// var tmp = WScript.StdIn.ReadAll()
> //// var TEMP = tmp.replace(/(\d\d\d\d-.+:\d\d )/g, AddDow) // g HERE
ONLY
> //// WScript.Echo(TEMP)
>
> var stdin = WScript.StdIn
> var stdout = WScript.StdOut
> var str, RE = /(\d\d\d\d.+:\d\d )/
>
> while (!stdin.AtEndOfStream) {
> str = stdin.ReadLine()
> if (RE.test(str)) {
> str = str.replace(RE, AddDow)
> stdout.WriteLine(" " + str) } }
>
> // End
>
> Sample output :
>
> 2014-01-10 14:29 Fri 1,165,170 $CURRASH.PNG
> 2014-03-05 00:48 Wed 3,058 SHIUMING.TXT
A normal person would perhaps prefer:
2014-01-10 14:29 free
2014-03-05 00:48 married
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-08-20 03:22 -0700 |
| Message-ID | <f86392cf-0eb7-419f-bf8c-6b5f7753e1af@googlegroups.com> |
| In reply to | #35529 |
On Sunday, August 19, 2018 at 9:49:38 PM UTC+1, Evertjan. wrote:
> Dr J R Stockton wrote on 19 Aug 2018 in comp.lang.javascript:
> > function AddDow(match) { return match + " " +
> > new Date(match.replace(/-/g, "/")).toString().substring(0, 3) }
>
> I would think there is no use for the replace function here.
Variable "match" holds an ISO 8601 date, format YYYY-MM-DD. In
the past, I have always found that new Date() gives NaN for that,
but accepts YYYY/MM/DD. So I put the ".replace" by force of habit.
It might not have been necessary in Win7 JScript. Provoked by you,
I removed it - and found that it was necessary, so un-removed it.
Perhaps I should say that AddDow, as is, might not do in ECMAscript,
unless the specification (for all necessary versions) says that
day-of-week must come first, and is always obeyed.
> > Sample output :
> >
> > 2014-01-10 14:29 Fri 1,165,170 $CURRASH.PNG
> > 2014-03-05 00:48 Wed 3,058 SHIUMING.TXT
>
> A normal person would perhaps prefer:
>
> 2014-01-10 14:29 free
> 2014-03-05 00:48 married
The format of the rest of a line is, as yet, un-optimised.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web