Page 1 of 1
Windows 8.1 and 'findstr' is not recognized????
Posted: 17 Nov 2014 21:56
by josephf
I wrote a script to that handles the conversion of images via the ffmpeg binary, but have a user that briefly sees the "findstr is not recognized....." before it immediately closes on him/her. Any ideas? I've searched google but haven't found any correlation between findstr and Windows 8.1. I have no problem posting the batch file, but don't see it as pertinent.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 17 Nov 2014 21:59
by Ed Dyreen
can u post the code that doesn't work ?
what does the user see if he types the following command at the console ?
what does the user see if he types the following command in the batchfile and runs it ?
what does the user see if he types the following command in the batchfile and runs it ?
the error he gets suggests findStr does not exist in any directory that is in the %path% variable.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 17 Nov 2014 22:23
by josephf
I asked the user to try "findstr /?" I haven't had a response yet, but it is bugging me more than the user. I haven't gotten a reply yet. My next step, after some research (and professional validation), was to inquire about %path%. But there is a language barrier and I figured I'd go to the pros.
Code: Select all
@setlocal enableextensions&@echo off&setlocal enabledelayedexpansion&set "vers=1.6"&title Nexus 9 Splash Tool v!vers!&color 0b&mode con cols=78 lines=45&cls&call :drawhead
set "videofilter="
set "showbeforeflashing=yesure"
set "showbeforerotating="
set "rotatesquares="
set "usedefaultviewer="
if exist "%~dp0sys\log\imageres" del /q "%~dp0sys\log\imageres"
set /a "expected_filesize=6291456"
set /a "aspectmultiplier=100000"
set /a "expected_pixels=%expected_filesize%/2"
set "loglevel=-loglevel debug"
set "hidebanner=-hide_banner"
set "ffmlog=>>"%~dp0sys\log\ffmpeg_log.txt" 2>&1"
if "%~1"=="stock" set "image_file=%~dp0sys\stock_binary\sp1.nb0"&set "base_name=Stock Google Splash Screen"&call :stock
set "image_file=%~1"
if not exist "%image_file%" call :nofile
if not exist "%~dp0sys\log\" mkdir "%~dp0sys\log"
set "irony="
cd /d "%~dp0"
for %%? in ("%image_file%") do set "base_name=%%~n?"&set "ext=%%~x?"&set "osize=%%~z?"
if /i "%ext%"==".bmp" goto :checkres
if /i "%ext%"==".jpg" goto :checkres
if /i "%ext%"==".jpeg" goto :checkres
if /i "%ext%"==".png" goto :checkres
if /i "%ext%"==".raw" if "%osize%"=="%expected_filesize%" call :flashit "%image_file%"
if /i "%ext%"==".rgb565" if "%osize%"=="%expected_filesize%" call :flashit "%image_file%"
if /i "%ext%"==".nb0" if "%osize%"=="%expected_filesize%" call :flashit "%image_file%"
if not defined irony if "%osize%"=="%expected_filesize%" call :flashit "%image_file%"
goto :checkres
:checkres
for /f "tokens=1-8* delims=," %%a in ('sys\bin\ffmpeg -i "%image_file%" 2^>^&1^|findstr /rxic:".*stream #0:0.*[0-9][0-9]x[0-9][0-9].*"') do (
echo.%%a >"%~dp0sys\log\imageres"
echo.%%b >>"%~dp0sys\log\imageres"
echo.%%c >>"%~dp0sys\log\imageres"
echo.%%d >>"%~dp0sys\log\imageres"
echo.%%e >>"%~dp0sys\log\imageres"
echo.%%f >>"%~dp0sys\log\imageres"
echo.%%g >>"%~dp0sys\log\imageres"
echo.%%h >>"%~dp0sys\log\imageres"
)
for /f "tokens=1-3 delims=x " %%d in ('type "%~dp0sys\log\imageres"^|findstr /rxic:".*[0-9][0-9]x[0-9][0-9].*"') do (set /a "width=%%d"&set /a "width=!width: =!"&set /a "height=%%e"&set /a "height=!height: =!")
if %width% gtr %height% goto :rotate
if defined rotatesquares if %width% equ %height% goto :rotate
set /a requiredaspect=%aspectmultiplier%*1536/2048
set /a aspectratio=%aspectmultiplier%*%width%/%height%
set /a pixels=%width%*%height%
if %aspectratio% neq %requiredaspect% goto :badresolution
if %pixels% neq %expected_pixels% goto :badresolution
goto :convertit
:badresolution
if "%aspectratio%"=="%requiredaspect%" echo.Auto resizing image.&set "videofilters=-vf "scale=1536:2048""&goto :resize
cls&call :drawhead&echo.&echo. Your image doesn't meet the required resolution of 1536x2048&echo.
:changeaspect
echo. Your image aspect ratio is different from the required 3:4 aspect ratio.&echo.
if %pixels% lss %expected_pixels% echo. Keep in mind that I can make your image bigger, but I can't add detail....
echo. ____________________________________________________________________________&echo. Please choose 1 or 2 and press ENTER&echo.&echo. 1 - Resize it by stretching or shrinking image ^(aspect ratio will change^)&echo. 2 - Keep aspect, but resize and crop ^(aspect ratio will stay the same^)&echo.
set /p ihatexp=?
if "%ihatexp%"=="1" set "videofilters=-vf "scale=1536:2048""&goto :resize
if "%ihatexp%"=="2" (
if %requiredaspect% gtr %aspectratio% set "videofilters=-vf "scale=1536:-1, crop=1536:2048""
if %requiredaspect% lss %aspectratio% set "videofilters=-vf "scale=-1:2048, crop=1536:2048""
goto :resize)
goto :badresolution
:resize
set "out_path=sys\temp"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -i "%image_file%" %videofilters% -y "%~dp0%out_path%\%base_name%.png"
call "%~dpnx0" "%~dp0%out_path%\%base_name%.png"
goto :convertit
:rotate
:again
cls&call :drawhead&echo.&echo.
echo. The image has to be rotated either left or right.
if defined showbeforerotating if not defined usedefaultviewer echo. CLOSE the image when you are done to continue
echo. Please choose 1 or 2 and press ENTER&echo.
echo. ____________________________________________________________________________
echo. 1 - Rotate Image Left&echo. 2 - Rotate Image Right&echo.
if defined showbeforerotating (
ping -n 3 127.0.0.1> nul
if defined usedefaultviewer start "" "%image_file%"
if not defined usedefaultviewer rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %image_file%
)
set /p "ihatexp= ?"
if "%ihatexp%"=="2" set "videofilters=-vf "transpose=1""&goto :ready
if "%ihatexp%"=="1" set "videofilters=-vf "transpose=2""&goto :ready
goto :again
:ready
set "out_path=sys\temp"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -i "%image_file%" %videofilters% -y "%~dp0%out_path%\%base_name%.png"
call "%~dpnx0" "%~dp0%out_path%\%base_name%.png"
exit
:convertit
cls&call :drawhead
set "out_path=sys\raw images"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
if exist "%~dp0%out_path%\!base_name!.raw" del /q "%~dp0%out_path%\!base_name!.raw"
echo.&echo. Converting file into a raw 2 byte per pixel rgb565 image..
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -i "%image_file%" -f rawvideo -vcodec rawvideo -pix_fmt rgb565 -y "%~dp0%out_path%\!base_name!.raw"
for %%? in ("%~dp0%out_path%\!base_name!.raw") do set /a "out_filesize=%%~z?"
if not "!out_filesize!" == "%expected_filesize%" goto :badsize
call :flashit "%~dp0%out_path%\%base_name%.raw"
exit
:stock
for %%? in ("%~dp0sys\stock binary\sp1.nb0") do set "out_filesize=%%~z?"
cls&call :drawhead
if exist "%~dp0sys\stock binary\sp1.nb0" echo.&echo. Preparing to flash a binary copy of the stock flash screen.&call :flashit "%~dp0sys\stock binary\sp1.nb0"
cls&call :drawhead&echo. The stock binary image is missing, please re-download program.
ping -n 4 127.0.0.1> nul
start "" http://forum.xda-developers.com/nexus-9/themes-apps/tool-splash-screen-flasher-v1-0-t2931575/post56561564#post56561564&pause>nul&exit
exit
:flashit
if not "%base_name%"=="Stock Google Splash Screen" if defined showbeforeflashing call :regen "%~1"
cls&call :drawhead&echo. ____________________________________________________________________________&echo.
"%~dp0sys\bin\adb.exe" kill-server&&echo.
echo. Your image is ready to be flashed^!
echo. Press any key to reboot to the bootloader.&&pause>nul&&echo.______________________________________________________________________________&&"%~dp0sys\bin\adb.exe" reboot bootloader&&echo.&&echo.After your bootloader screen shows up, please verify that&&echo.you are in ^"FASTBOOT USB^" mode and press enter to flash the splash image.&&pause>nul
if exist "%~1" (
for %%? in ("%~1") do set /a "out_filesize=%%~z?"
if not "!out_filesize!"=="%expected_filesize%" (goto :badsize
) else ("%~dp0sys\bin\fastboot.exe" flash splash1 "%~1"&&echo.______________________________________________________________________________&&echo.&&echo.&&echo. Done..Press any key to reboot to your new splash screen..&&pause>nul&&"%~dp0sys\bin\fastboot.exe" reboot&&"%~dp0sys\bin\adb.exe" kill-server)
) else (goto :nofile)
rd /s /q "%~dp0\sys\temp"
exit
:regen
set "out_path=sys\temp"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -f rawvideo -vcodec rawvideo -pix_fmt rgb565 -s 1536x2048 -i "%~1" -y "%~dp0%out_path%\%base_name%_test.png"
echo.&echo. This is what it looks like when it is converted back into a viewable image.
echo. Close the image when you are done to continue&ping -n 4 127.0.0.1> nul
if defined usedefaultviewer start "" "%~dp0%out_path%\%base_name%_test.png"
if not defined usedefaultviewer rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %~dp0%out_path%\%base_name%_test.png
goto :eof
:badsize
cls&call :drawhead&echo.
echo. The image you flash has to be 1536x2048..
echo. The filesize of the raw image in turn would
echo. be %expected_filesize%.&echo.&echo.Your raw image size is !out_filesize!&echo.&echo.&echo. Press Enter to delete file and exit.&pause>nul
del /q "%~dp0%out_path%\!base_name!.raw"&"%~dp0sys\bin\adb.exe" kill-server
exit
:drawhead
echo. __________________________________________________________________________-_-
echo. ____________________________________________________________________________
echo.
echo. Nexus 9 Splash Tool: v%vers% by makers_mark
echo. ____________________________________________________________________________&echo.
if not defined image_file (echo. Loading..............) else (echo. File: "%base_name%%ext%")
if defined width if defined height echo. Resolution: %width%x%height%
if defined out_filesize (echo. Size: %out_filesize%) else (echo. Size: %osize% ^(image hasn't been converted^))
echo. Target Size: %expected_filesize%
echo. ____________________________________________________________________________
echo.
goto :eof
:nofile
cls&call :drawhead&echo.&echo. You have to drag and drop your png, bmp, or jpg file onto&echo.the %~nx0 batch file&echo.&pause>nul&"%~dp0sys\bin\adb.exe" kill-server
exit
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 17 Nov 2014 22:38
by Ed Dyreen
so for all we know, the file simply does not exist or the %path% variable does not contain 'C:\WINDOWS\system32' which is the default location of file 'findStr.EXE'.
using 'findStr.EXE' instead of just 'findStr' narrows the possibility of a wrong file being run, windows will prefer and run 'findStr.BAT' instead of 'findStr.EXE' if it finds it in the current dir or in a dir that is on the %path% variable, but that is not the case here.
using 'goto' to call a function is ill-advised, this leads to what is referred to as spaghetti code, it can easily be avoided by using 'call'.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 17 Nov 2014 22:54
by josephf
Thank you Ed and all of you other experts here. I was baffled when I could get it to work on a windows 8 computer, and my first instinct was that something had disabled command extensions on the users computer (win8.1). You are more than likely correct; the user just responded that findstr /? created the same error. I asked to see if echo.%path% produced "windows\system32"
We'll see. But probably not. I never though you could survive without the most basic path in your "path" But I guess if you're not running command intensive programs every once in awhile, you might not notice.
Thanks again.
EDIT:Yes, the spaghetti code. I rushed this out and at first was trying to make it a pretty much drag and drop (very little to no user interaction) program, then it progressed where my much loved calls were needed. I haven't totally came back to where it will be menu driven and with nothing but calls. I do despise gotos, and hardly ever use them.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 06:16
by foxidrive
A very long time ago GOTO got a bad rep (in BASIC programs) but I wouldn't avoid using it just because of that.
FWIW using CALL is very slow, and it has other bugs.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 07:26
by Squashman
heck, I use GOTO :EOF in just about every batch file I write these days.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 07:47
by ShadowThief
Squashman wrote:heck, I use GOTO :EOF in just about every batch file I write these days.
I didn't realize there were even other ways to end a function.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 18:29
by josephf
foxidrive wrote:A very long time ago GOTO got a bad rep (in BASIC programs) but I wouldn't avoid using it just because of that.
FWIW using CALL is very slow, and it has other bugs.
About the only time I use goto (aside from my ever-changing whim up above) is in menus to take care of errors in keypresses, that are in functions. I usually name the label inside the function (right above the option menu) ":keepitinthecall" I am never sure if it will lose it's identity (where it came from). I didn't know that call was buggy, I knew it was slow, but that isn't a concern with what I usually do. I have some looking up to do concerning the bugs though, thanks!
ShadowThief wrote:I didn't realize there were even other ways to end a function.
I know this is a small but very brilliant community, a lot of people know others reactions and what not. I however don't, so I'm not sure if you are being sarcastic, or if I'm wrong in saying what I'm getting ready to. But "exit /b" will return to right after where a call was issued, right?
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 18:35
by ShadowThief
josephf wrote:ShadowThief wrote:I didn't realize there were even other ways to end a function.
I know this is a small but very brilliant community, a lot of people know others reactions and what not. I however don't, so I'm not sure if you are being sarcastic, or if I'm wrong in saying what I'm getting ready to. But "exit /b" will return to right after where a call was issued, right?
Wasn't being sarcastic. Totally forgot about exit /b working for ending functions; I only ever use it to end the script.
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 20:44
by Ed Dyreen
foxidrive wrote:CALL has other bugs.
what other bugs ?
ps; i screwed your original post, sorry
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 18 Nov 2014 23:08
by josephf
Ed Dyreen wrote:foxidrive wrote:CALL has other bugs.
what other bugs ?
ps; i screwed your original post, sorry
foxidrive wrote:A very long time ago GOTO got a bad rep (in BASIC programs) but I wouldn't avoid using it just because of that.
FWIW using CALL is very slow, and it has other bugs.
sans
Re: Windows 8.1 and 'findstr' is not recognized????
Posted: 19 Nov 2014 05:22
by penpen
ShadowThief wrote:josephf wrote:ShadowThief wrote:I didn't realize there were even other ways to end a function.
I know this is a small but very brilliant community, a lot of people know others reactions and what not. I however don't, so I'm not sure if you are being sarcastic, or if I'm wrong in saying what I'm getting ready to. But "exit /b" will return to right after where a call was issued, right?
Wasn't being sarcastic. Totally forgot about exit /b working for ending functions; I only ever use it to end the script.
At least when using winxp the "exit /b" internally uses the "goto :EOF" functionality.
If you want to check this, you should create a batch file "test.bat":
Then open a command shell, and type:
Code: Select all
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
Z:\>cmd /V:OFF /E:OFF
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
Z:\>test.bat
Das Sprungziel - EOF wurde nicht gefunden.
Z:\>
Note: "Das Sprungziel - EOF wurde nicht gefunden." is the error message, used by "goto :EOF", if the label EOF is not defined.
penpen