Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35523

Re: Batch pipe JScript question

Newsgroups comp.lang.javascript
Subject Re: Batch pipe JScript question
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <f15ab55b-562a-4005-a351-230861244b24@googlegroups.com>
Date 2018-08-18 23:07 +0200
Message-ID <XnsA942EB3CBFE8Eeejj99@194.109.6.166> (permalink)

Show all headers | View raw


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)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web