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
![Wink ;)](./images/smilies/icon_wink.gif)
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