Script package formatting the output of a cli application

I have a very small batch of script that extracts quite a few files. The script is designed to deliver compressed data to other users.

Now my problem is that this compression tool outputs a ton of data to the cmd window. I think this will confuse a lot of use, because the output really "works." It basically shows the percentage with each line and how it is unpacked at what speed (processor and hard drive). A lot of confusing data that no one should see. Now I don’t really like to suppress the entire output of the program, giving the user feedback on how far from decompression was already important, in my opinion. So is it possible to redirect the output and read only the first three digits of this output and convey it to users in one line? So users only see advancing percantage (on one line), and not 20 new lines every second with all this data?

Here is an example of what it looks like at the moment: http://i.imgur.com/5w5LH.png The compression tool is SREP, my OS is Win 7 x64.

+3
source share
2 answers

Here is a simple hybrid / JScript script package that I think will do what you want.

show3.bat

@if (@X)==(@Y) @end /* harmless hybrid line that begins a JScrpt comment

::: Batch part ::::
@cscript //nologo //e:JScript "%~f0"
@exit /b

*** JScript part ***/
while( !WScript.StdIn.AtEndOfStream ) {
  WScript.StdOut.Write( '\x08\x08\x08' + WScript.StdIn.ReadLine().substr(0,3) );
}
WScript.StdOut.WriteLine();

Using:

yourCommand | show3

the script can be simplified to pure JScript, but then it will not be so convenient:

show3.js

while( !WScript.StdIn.AtEndOfStream ) {
  WScript.StdOut.Write( '\x08\x08\x08' + WScript.StdIn.ReadLine().substr(0,3) );
}
WScript.StdOut.WriteLine();

Using:

yourCommand | cscript //nologo show3.js

EDIT As jeb commented, you won't need to use redist to use this solution.

I took some of the concepts in a jeb answer and combined the whole process into one hybrid script. There is no need for a separate show3 file.

@if (@X)==(@Y) @end /* harmless hybrid line that begins a JScrpt comment

:: ***** Batch part ******
@echo off

REM whatever batch code you need goes here

yourCommand | cscript //nologo //e:JScript "%~f0"

REM whatever batch code you need goes here

exit /b

****** JScript part ******/
while( !WScript.StdIn.AtEndOfStream ) {
  WScript.StdOut.Write( '\x08\x08\x08' + WScript.StdIn.ReadLine().substr(0,3) );
}
WScript.StdOut.WriteLine();

yourCommand , . , , yourCommand 2>&1, stderr stdout.

"yourCommand.bat" . , .

@echo off
for /l %%A in (1 1 100) do (
  echo %%A   "I don't want to see this quoted text"
  for /l %%B in (1 1 50000) do rem
)

, , jeb. .

@echo off
if "%~1"==":show3" goto :show3
REM whatever batch code you need goes here

(yourCommand & echo EOF) | "%~f0" :show3

REM whatever batch code you need goes here
exit /b

:show3
setlocal enableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
:read
set "ln="
set /p "ln="
if not defined ln goto :read
for /f "tokens=1* delims= " %%A in ("!ln!") do if "%%A%%B" equ "EOF" (
  echo(
  exit /b
)
<nul set /p "=!ln:~0,3!   !cr!"
goto :read

. EOF, . .

+4

Windows, , , FOR/F-Loop.

for /f "delims=" %%a in ( 7z packit... ) do ...
, for-loop 7z, .

- .
( CMD-).

-

@echo off
echo start
setlocal EnableDelayedExpansion
if "%1"=="internal" goto :readThread
start /b cmd /c ""%~f0" internal"

rem *** myPacker pack here and redirect the output
del archive.7z
del output.tmp
start "title" /b /wait cmd /c  "%ProgramFiles%\7-Zip\7z" u  archive \tempx\*.rtf \tempx\*.pdf ^> output.tmp
echo EOF>>output.tmp
echo ENDE
:waitForEnd
(
> lock (
  rem
) || goto :waitForEnd
) 2> nul
exit /b

:readThread

for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
echo ####!cr!x
echo(
<output.tmp ( 
    echo ## before
    call :readData 2> lock
    echo after
)
exit /b

:readData
set "var="
set /p var=
if "!var!"=="EOF" exit /b
if defined var (
  <nul set /p ".=Processing files, currently at !var:~0,4!!CR!"
)
goto :readData
+5

All Articles