CPU History on title

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#16 Post by penpen » 03 Dec 2013 07:56

As "for /F" is buffering,
"for/L,set/P" is not reliable when NL/CR are involved, and
you don't want to execute "typeperf ..." multiple times,
the only other idea is to use JSript to read the output of "typeperf ...".
Jscript should be able to read the typeperf output lines as fast as they are created (at least i hope it).

But actual i have not much time, so i have to do it later.

penpen

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#17 Post by penpen » 03 Dec 2013 14:39

So here is the JScript/batch hybrid script version:

Code: Select all

@if (true == false) @then /* 
@echo off
if "%~1" == "" goto :initiate
goto :%~1


:initiate
rem   cls
rem   test source
rem   cscript //NOLOGO //E:JScript "%~f0" "%~f0" "source"
   cscript //NOLOGO //E:JScript "%~f0" "%~f0" "source" | "%~f0" processLines
rem   echo finished successfully
   goto :eof


:source
   rem this is my simulation of typeperf, just replace it with the right one
   setlocal enableDelayedExpansion
   set "ip=192.168.0.222"
   set "ip=1.1.1.1"
   echo "(PDH-CSV 4.0)","\Processore(_Total)\%% Tempo Processore"
   (ping -n 1 -w 100 %ip%)>nul

   set "line="!date! !time!","0.000000""
   set "line=!line:,=.!"
   set "line=!line:"."=","!"

   for /L %%a in (1,1,5) do (
      echo !line!
      (ping -n 1 -w 100 %ip%)>nul
   )

   for /L %%a in (10,5,90) do for /L %%b in (123456,400000,923456) do (
      set "line="!date! !time!","%%a.%%b""
      set "line=!line:,=.!"
      set "line=!line:"."=","!"

      echo !line!
      (ping -n 1 -w 100 %ip%)>nul
   )

   set "line="!date! !time!","100.000000""
   set "line=!line:,=.!"
   set "line=!line:"."=","!"

   for /L %%a in (1,1,5) do (
      echo !line!
      (ping -n 1 -w 100 %ip%)>nul
   )
   endlocal


   rem following line is needed to terminate the JScript part.
   echo quit
   goto :eof


:processLines
   mode con cols=45 lines=1

   setlocal enableDelayedExpansion
rem   echo:%0: started

   set S=_,.-ùïî
   set Bcpu=K

   set "buffer="
   set "line="
   set "endOfStream=q"
:readkey
   set "input="
   set /p "input="
   if DEFINED input goto :inputAvailable
   goto :readkey

:inputAvailable
   set "buffer=%buffer%%input%"
rem   echo:%0: input="%input%",   buffer="%buffer%"
   
:detectLine
   if not defined buffer goto :noBuffer
   set "line=!buffer:*#=!"
   if defined line (
      set "line=!buffer:%line%=!"
   ) else (
      set "line=!buffer!"
   )

   if defined line (
      set "buffer=%buffer:*#=%"
rem      echo line found: "%line:~0,-1%", buffer="!buffer!"
      set "line=!line:~0,-1!"

      if defined line (
         set "v=!line:*\=\!"
         if not !v! == !line! set "v="
      ) else (
         set "v="
      )
      if defined v (
         set cpu=!v:*,=!
         set cpu=  !cpu:~1,-6!
         (set /a i=!cpu:~0,-2!*6/100)>nul
         for %%b in (!i!) do @(set Bcpu=!Bcpu!!S:~%%b,1!)
         set Bcpu=!Bcpu:~-30!
         title CPU:!cpu:~-5!%%  !Bcpu!
      )

      goto :detectLine
   )

:noBuffer
   set "isEndOfStream=!input:%endOfStream%=%endOfStream%_!"
   if !input! == !isEndOfStream! goto :readkey

rem   echo:%0: leaving
   endlocal


goto :eof
*/
@end


if (WScript.Arguments.Unnamed.length >= 1) {
   var cmdLine = "\"" + WScript.Arguments.Unnamed.Item (0) + "\"";
   for (var i = 1; i < WScript.Arguments.Unnamed.length; ++i) {
      cmdLine += " \"" + WScript.Arguments.Unnamed.Item (i) + "\"";
   }
   var wshShell = new ActiveXObject ("WScript.Shell");
   var program = wshShell.Exec (cmdLine);
   var line;

   while ((line = program.Stdout.ReadLine ()) != "quit" ) {
      line = line.replace ('\r', ' ');
      WScript.StdOut.Write (line + "#");
   }
}
   
WScript.Echo ("quit");
You only have to replace my typeperf "simulation" with the "real" one.

penpen

Edit: Added support for long batch filename with spaces, a mode command to shrink the window to 1x45,
and improved the simulation so you only have to set variable ip to change the ping target.
Edit2: The current version contains a problem in recomputing the line, and it also has exiting problems when a program sends unfinished last lines (whatever the line contains, '\r' or other text).
A version that fixed these bugs is available here:
http://www.dostips.com/forum/viewtopic.php?p=30482#p30482
Last edited by penpen on 09 Dec 2013 08:21, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: CPU History on title

#18 Post by foxidrive » 03 Dec 2013 19:07

It's interesting penpen.

I just ran it without examining it at all to see how it functions.

The two comments I'd make based upon that is that it doesn't support a long batch filename with spaces,
and a mode command to shrink the cmd window would make it neater.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#19 Post by penpen » 04 Dec 2013 12:35

I've changed the code above to add long filename support and the mini-mode command.

penpen

ashleyco
Posts: 3
Joined: 03 Sep 2013 23:46
Contact:

Re: CPU History on title

#20 Post by ashleyco » 05 Dec 2013 03:28

The insert in the first post stands out as before.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: CPU History on title

#21 Post by einstein1969 » 07 Dec 2013 08:39

penpen,

I have difficult to understand what do you do.

You have encapsulated the program that generate the output in line (with CR only?)

The jscript seem substitute the line with \r (0x0D=CR) with space (but the LF? is not substitute?)

Than the jscript add at the end of this line a "#".

Than send the line without a LF/CR.

Is correct what I understand?

Einstein1969

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#22 Post by penpen » 07 Dec 2013 15:39

The JScript part runs a program given by parameter and reads this programs output linewise, automatically removing the final "\r\n".
The bad thing is that some dos programs on (my) WinXP home, for example the german version of ping.exe, produces an additional "\r" at the end of each line.
Because of that i replaced "\r" with the space character.
After that i write the line to the pipe, seperating each line with a "#" to avoid using "\n", so that the set command works with no error;
except the known limitations of set, which should be no problem when using the typeperf tool.
At the receiver side of the pipe each line is rebuild without a (buffering) for loop, so the data is processed immediately.

penpen

Edit: I've just found out, that there is a bug using doublequote chars; so as soon, as i have the time to do that i will solve that issue.
Edit2: It was no doublequote problem; it was a problem in recomputing the line, a newer version can be found here:
http://www.dostips.com/forum/viewtopic.php?p=30482#p30482
Last edited by penpen on 09 Dec 2013 08:18, edited 1 time in total.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: CPU History on title

#23 Post by einstein1969 » 08 Dec 2013 09:56

penpen wrote:The JScript part runs a program given by parameter and reads this programs output linewise, automatically removing the final "\r\n".
The bad thing is that some dos programs on (my) WinXP home, for example the german version of ping.exe, produces an additional "\r" at the end of each line.
Because of that i replaced "\r" with the space character.
After that i write the line to the pipe, seperating each line with a "#" to avoid using "\n", so that the set command works with no error;
except the known limitations of set, which should be no problem when using the typeperf tool.
At the receiver side of the pipe each line is rebuild without a (buffering) for loop, so the data is processed immediately.

penpen

Edit: I've just found out, that there is a bug using doublequote chars; so as soon, as i have the time to do that i will solve that issue.


Ok, now this is clear. The code read a line and if there is an \r , remove this.

But I have several question, but once at time ;)

I have substitute the "source" with Typeperf.

Typeperf produce output like this:

Code: Select all

/r/n"text","text"/r/n"text","text"/r/n"text"/r/n"text","text" ... /r/n/r/r

only at the end we obtain double /r


and

Code: Select all

@echo off
if "%~1" == "" goto :initiate
goto :%~1


:initiate
rem   cls
rem   test source
   cscript //NOLOGO //E:JScript "%~f0" "%~f0" "source"
rem   cscript //NOLOGO //E:JScript "%~f0" "%~f0" "source" | "%~f0" processLines
rem   echo finished successfully
   goto :eof

:source

  typeperf "\Processore(_Total)\%% Tempo Processore" -si 2 -sc 3

  rem following line is needed to terminate the JScript part.
  echo quit

goto :eof

*/
@end


if (WScript.Arguments.Unnamed.length >= 1) {
   var cmdLine = "\"" + WScript.Arguments.Unnamed.Item (0) + "\"";
   for (var i = 1; i < WScript.Arguments.Unnamed.length; ++i) {
      cmdLine += " \"" + WScript.Arguments.Unnamed.Item (i) + "\"";
   }
   var wshShell = new ActiveXObject ("WScript.Shell");
   var program = wshShell.Exec (cmdLine);
   var line;

   while ((line = program.Stdout.ReadLine ()) != "quit" ) {
      //WScript.Echo ("Line:"+"'"+line+"'");
      line = line.replace ('\r', ' ');
      WScript.StdOut.Write (line + "#");
      //WScript.Echo ("Line:"+"'"+line+"'");
   }
}
WScript.Echo ("quit!");


produce an endless output!

Code: Select all

>test_replace_newline.cmd
#"(PDH-CSV 4.0)","\\ACER-ASP-5100\Processore(_Total)\% Tempo Processore"#"12/08/2013 16:40:20.181","
0.000000"#"12/08/2013 16:40:22.181","2.343750"#"12/08/2013 16:40:24.181","10.156250"#Uscita in corso
quit################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
...


second question:

is for /L buffering? (What do you mean by buffered?)

in the previus post i have see that without for /L the problem with new lines there is too. But with no new line?

First test with no new line.

Code: Select all

first run:
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "@echo off&for /L %a in (1,1,2000) do (set v=&set /P v=&if defined v echo [%a]!v!)"
[1]1#
[2]2#
[3]3#
[4]pause#
[5]4#
[6]5#
[7]6#

next runs
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "@echo off&for /L %a in (1,1,2000) do (set v=&set /P v=&if defined v echo [%a]!v!)"
[1]1#  2#  3#  pause#
[2]4#
[3]5#
[4]6#


now without For /L

test:

Code: Select all

first run(cold run):
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.
0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "(@echo
off&set v=&set /P v=&echo [1]!v!&set v=&set /P v=&echo [2]!v!&set v=&set /P v=&echo [3]!v!&set v=&se
t /P v=&echo [4]!v!&set v=&set /P v=&echo [5]!v!&set v=&set /P v=&echo [6]!v!&set v=&set /P v=&echo
[7]!v!&set v=&set /P v=&echo [8]!v!)"
[1]1#
[2]2#
[3]3#
[4]pause#
[5]4#
[6]5#
[7]6#
[8]!v!

next runs:
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.
0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "(@echo
off&set v=&set /P v=&echo [1]!v!&set v=&set /P v=&echo [2]!v!&set v=&set /P v=&echo [3]!v!&set v=&se
t /P v=&echo [4]!v!&set v=&set /P v=&echo [5]!v!&set v=&set /P v=&echo [6]!v!&set v=&set /P v=&echo
[7]!v!&set v=&set /P v=&echo [8]!v!)"
[1]1#  2#  3#  pause#
[2]4#
[3]5#
[4]6#
[5]!v!
[6]!v!
[7]!v!
[8]!v!


however, it seems that there is a problem with the first run that does not depend on For /L
Perhaps it is disconnected from the newline problem?

and...

In the previus example there are spaces beetween #1 and #2! , why?

Code: Select all

(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "@echo off&for /L %a in (1,1,2000) do (set v=&set /P v=&if defined v echo [%a]'!v!')"
[1]'1#  2#  3#  pause#  '
[2]'4#  '
[3]'5#  '
[4]'6#  '


EDIT: I have understund the last problem regard the space. i don't have used the double quote around the variable in set /p. I will redo the test with the sintax set /P "=1#"

Einstein1969

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#24 Post by penpen » 08 Dec 2013 13:46

einstein1969 wrote:I have substitute the "source" with Typeperf.

Typeperf produce output like this:

Code: Select all

/r/n"text","text"/r/n"text","text"/r/n"text"/r/n"text","text" ... /r/n/r/r

only at the end we obtain double /r
and
(...: JScript code)
produce an endless output!

Code: Select all

>test_replace_newline.cmd
#"(PDH-CSV 4.0)","\\ACER-ASP-5100\Processore(_Total)\% Tempo Processore"#"12/08/2013 16:40:20.181","
0.000000"#"12/08/2013 16:40:22.181","2.343750"#"12/08/2013 16:40:24.181","10.156250"#Uscita in corso
quit################################################################################################
...
This should not happen, but i guess (i'm not sure what "Uscita in corso" means, i assume it is a kind of an error message) it is because of a missing newline before the "echo quit" in initialization part; i didn't expected something like that (bug found), but i hope it should be avoided by adding an additional echo prior the above echo:

Code: Select all

:source
::   ...
   rem following line is needed to terminate the JScript part.
   echo(
   echo quit
   goto :eof

einstein1969 wrote:second question:
(...) (What do you mean by buffered?)
WIth buffering i mean, that either the input, or the output, or both is stored before it is processed:

Code: Select all

Z:\>(echo 1,&echo 2,& echo 3,&echo pause,&((ping 192.168.0.10 -n 1 -w 5000)>nul
2>nul)&echo 4,&echo 5,& echo 6,) | (@echo off&find /N ",")

versus

Z:\>(echo 1,&echo 2,& echo 3,&echo pause,&((ping 192.168.0.10 -n 1 -w 5000)>nul
2>nul)&echo 4,&echo 5,& echo 6,) | (@echo off&for /F %a in ('find /N ","') do ec
ho %a)
The upper version is not buffering, and you see the output immediately,
while the line below displays all after the last line was produced.

einstein1969 wrote:second question:

is for /L buffering? (...)

in the previus post i have see that without for /L the problem with new lines there is too. But with no new line?

First test with no new line.

Code: Select all

first run:
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "@echo off&for /L %a in (1,1,2000) do (set v=&set /P v=&if defined v echo [%a]!v!)"
[1]1#
[2]2#
[3]3#
[4]pause#
[5]4#
[6]5#
[7]6#

next runs
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "@echo off&for /L %a in (1,1,2000) do (set v=&set /P v=&if defined v echo [%a]!v!)"
[1]1#  2#  3#  pause#
[2]4#
[3]5#
[4]6#


now without For /L

test:

Code: Select all

first run(cold run):
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.
0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "(@echo
off&set v=&set /P v=&echo [1]!v!&set v=&set /P v=&echo [2]!v!&set v=&set /P v=&echo [3]!v!&set v=&se
t /P v=&echo [4]!v!&set v=&set /P v=&echo [5]!v!&set v=&set /P v=&echo [6]!v!&set v=&set /P v=&echo
[7]!v!&set v=&set /P v=&echo [8]!v!)"
[1]1#
[2]2#
[3]3#
[4]pause#
[5]4#
[6]5#
[7]6#
[8]!v!

next runs:
(<nul set /p =1#&<nul set /p =2#&<nul set /p =3#&<nul set /p =pause#&((ping 192.168.
0.10 -n 1 -w 5000)>nul2>nul)&<nul set /p =4#&<nul set /p =5#&<nul set /p =6#)| cmd /V:ON /c "(@echo
off&set v=&set /P v=&echo [1]!v!&set v=&set /P v=&echo [2]!v!&set v=&set /P v=&echo [3]!v!&set v=&se
t /P v=&echo [4]!v!&set v=&set /P v=&echo [5]!v!&set v=&set /P v=&echo [6]!v!&set v=&set /P v=&echo
[7]!v!&set v=&set /P v=&echo [8]!v!)"
[1]1#  2#  3#  pause#
[2]4#
[3]5#
[4]6#
[5]!v!
[6]!v!
[7]!v!
[8]!v!

however, it seems that there is a problem with the first run that does not depend on For /L
Perhaps it is disconnected from the newline problem?
I don't see any problem here, because no data is lost - only one line is transmitted via pipe ("1# 2# 3# pause# 4# 5# 6# ") and it is received fully; the contents of the parts depend on timing mainly produced by the OSes process scheduler, i assume if you repeat the examples above often enough you get any possible partitioning of the line with both methods.
Some of the partitionings are more probable than others, and the propabilities surely depend on the code executed, so you see the difference above in most runs, i think.
I think for /L is not buffering, but up to now i haven't tested it fully.

penpen

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: CPU History on title

#25 Post by einstein1969 » 08 Dec 2013 14:46

For first question:
"Uscita in corso" is not a error, is the final output:
"Uscita in corso" = "Exiting"

For the buffered, i see the difference that you mean.

the For /L is not buffered for me. In the previus test all the output is displayed immediatly.

The timing that influence the set /p influence the data with newline also.

There is no data lost if timing is respected (the receiver must be started?), i have added a delay.
This is not buffered.

Code: Select all

(ping 192.168.0.10 -n 1 -w 1000>nul & ( for /L %a in (1,1,20) do @(echo %a,))& echo pause,&ping 192.168.0.10 -n 1 -w 1000>nul&echo 21&echo 22) | for /L %a in (1,1,23) do @(set "v=" & set /P "v=" & call set/p "=v=%v%"<nul)
v=1, v=2, v=3, v=4, v=5, v=6, v=7, v=8, v=9, v=10, v=11, v=12, v=13, v=14, v=15, v=16, v=17, v=18, v=19, v=20, v=pause, v=21 v=22


or

Code: Select all

(ping 192.168.0.10 -n 1 -w 1000>nul & ( for /L %a in (1,1,3) do @(echo %a,))& echo pause,&ping 192.168.0.10 -n 1 -w 1000>nul&echo 4,&echo 5,&echo 6,) | cmd /q /v:on /c "for /L %a in (1,1,23) do (set "v=" & set /P "v=" & if defined v echo v=!v!)"
v=1,
v=2,
v=3,
v=pause,
v=4,
v=5,
v=6,


Einstein1969
Last edited by einstein1969 on 08 Dec 2013 15:25, edited 1 time in total.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: CPU History on title

#26 Post by einstein1969 » 08 Dec 2013 15:09

i think that the problem with the endless output is the exiting condition of the while in jscript.
that don't remove /r

Code: Select all

 while ((line = program.Stdout.ReadLine ()) != "quit" )


this also work

Code: Select all

:source
::   ...
   rem following line is needed to terminate the JScript part.
   echo(
   echo quit
   goto :eof


einstein1969

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#27 Post by penpen » 09 Dec 2013 08:14

einstein1969 wrote:There is no data lost if timing is respected (the receiver must be started?), i have added a delay.
...
When using WinXp home (actual patch level) there is data loss:

Code: Select all

Z:\>(ping 192.168.0.10 -n 1 -w 1000>nul & ( for /L %a in (1,1,20) do @(echo %a,)
)& echo pause,&ping 192.168.0.10 -n 1 -w 1000>nul&echo 21&echo 22) | for /L %a i
n (1,1,23) do @(set "v=" & set /P "v=" & call set/p "=v=%v%"<nul)
v=1, v=2, v=21 v=22 v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%
v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%v=%v%
Z:\>(ping 192.168.0.10 -n 1 -w 1000>nul & ( for /L %a in (1,1,3) do @(echo %a,))
& echo pause,&ping 192.168.0.10 -n 1 -w 1000>nul&echo 4,&echo 5,&echo 6,) | cmd
/q /v:on /c "for /L %a in (1,1,23) do (set "v=" & set /P "v=" & if defined v ech
o v=!v!)"
v=1,
v=2,
v=4,
v=5,


penpen

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: CPU History on title

#28 Post by penpen » 09 Dec 2013 08:16

This is a fixed version (i hope it contains no bugs anymore):

Code: Select all

@if (true == false) @then /* 
@echo off
if "%~1" == "" goto :initiate
goto :%~1


:initiate
   cscript //NOLOGO //E:JScript "%~f0" "%~f0" "source" | "%~f0" processLines
   goto :eof


:source
   rem this is my simulation of typeperf, just replace it with the right one
   setlocal enableDelayedExpansion
   set "ip=192.168.0.222"
   set "ip=1.1.1.1"
   echo "(PDH-CSV 4.0)","\Processore(_Total)\%% Tempo Processore"

   set "line="!date! !time!","0.000000""
   set "line=!line:,=.!"
   set "line=!line:"."=","!"

   for /L %%a in (1,1,5) do (
      echo !line!
   )

   for /L %%a in (10,1,90) do for /L %%b in (123456,100000,923456) do (
      set "line="!date! !time!","%%a.%%b""
      set "line=!line:,=.!"
      set "line=!line:"."=","!"

      echo !line!
   )

   set "line="!date! !time!","100.000000""
   set "line=!line:,=.!"
   set "line=!line:"."=","!"

   for /L %%a in (1,1,500) do (
      echo !line!
   )
   endlocal


   rem following line is needed to terminate the JScript part.
   echo(
   echo quit
   goto :eof


:processLines
   mode con cols=45 lines=1

   setlocal enableDelayedExpansion

   set S=_,.-ùïî
   set Bcpu=K

   set "buffer="
   set "line="
   set "endOfStream=q"
:readkey
   set "input="
   set /p "input="
   if DEFINED input goto :inputAvailable
   goto :readkey

:inputAvailable
   set "buffer=%buffer%%input%"
   
:detectLine
   if not defined buffer goto :noBuffer
   set "line=!buffer:*#=!"
   if defined line (
      if !buffer! == !line! (
         set "line="
      ) else (
         set "line=!buffer:#%line%=!#"
      )
   ) else (
      set "line=!buffer!"
   )

   if defined line (
      set "buffer=%buffer:*#=%"
      set "line=!line:~0,-1!"

      if defined line (
         set "v=!line:*\=\!"
         if not !v! == !line! set "v="
      ) else (
         set "v="
      )
      if defined v (
         set cpu=!v:*,=!
         set cpu=  !cpu:~1,-6!
         (set /a i=!cpu:~0,-2!*6/100)>nul
         for %%b in (!i!) do @(set Bcpu=!Bcpu!!S:~%%b,1!)
         set Bcpu=!Bcpu:~-30!
         title CPU:!cpu:~-5!%%  !Bcpu!
      )

      goto :detectLine
   )

:noBuffer
   set "isEndOfStream=!input:%endOfStream%=%endOfStream%_!"
   if !input! == !isEndOfStream! goto :readkey

   endlocal
   goto :eof
*/
@end


if (WScript.Arguments.Unnamed.length >= 1) {
   var cmdLine = "\"" + WScript.Arguments.Unnamed.Item (0) + "\"";
   for (var i = 1; i < WScript.Arguments.Unnamed.length; ++i) {
      cmdLine += " \"" + WScript.Arguments.Unnamed.Item (i) + "\"";
   }
   var wshShell = new ActiveXObject ("WScript.Shell");
   var program = wshShell.Exec (cmdLine);
   var line;

   while ((line = program.Stdout.ReadLine ()) != "quit" ) {
      line = line.replace ('\r', ' ');
      WScript.StdOut.Write (line + "#");
   }
}
   
WScript.Echo ("quit");

penpen

Post Reply