So I am trying to create a simple batch file for our customers to use for testing their files against certain tools like Ghostscript and imagemagick.
The issue is not with those, the issue is in fact that I select 0 at the menu item and it will goto :Inputdesignation instead of exit /b or eof
the first time that I select 0 but if I input the file name again and press 0 when it returns me to the menu, then it will exit. The first time it gives me an error of 'FINDSTR: Bad command line'. I am calling findstr for returning a value from a file which works when I turn on the echo :baseFolder, but not seeing why I get this error at this point in the batch file. I also don't have much experience with findstr and yes I have googled it.
For reference I have had :END at the end of the file and set it to go there and the same thing happens.
This will be run on win 7, win 8, server 2008, 2008 R2, 2012, and 2012 R2 in case you see any issues with any of that also.
If anyone can give me some input on this, it would be awesome. I have it up at pastebin.
Code: Select all
@ECHO off
IF NOT EXIST C:\Test_Ephe GOTO MakeTestDir
:CheckInput
IF NOT EXIST C:\Test_Ephe\Input GOTO MakeInputDir
:CheckOutput
IF NOT EXIST C:\Test_Ephe\Output GOTO MakeOutputDir
:Variables
setlocal enableextensions enabledelayedexpansion
Set EpheInput=C:\Test_Ephe\Input
Set EpheOutput=C:\Test_Ephe\Output
set dcma-batch="%DCMA_HOME%\WEB-INF\classes\META-INF\dcma-batch\dcma-batch.properties"
call:getvalue %dcma-batch% "batch.base_folder" "" baseFolder
::echo %baseFolder%
:getvalue
FOR /F "eol=; eol=[ tokens=1,2* delims==" %%i in ('findstr /b /l /i %~2= %1') DO set %~4=%%~j
GOTO InputDesignation
:Move
C:
Cd c:\Test_Ephe
CLS
GOTO Menu
:Menu
CLS
ECHO Welcome to the Ephesoft Command Line testing tool.
ECHO .
ECHO ...............................................
ECHO PRESS the number to select your task, or # to EXIT.
ECHO Your SharedFolders is located at %baseFolder%.
ECHO ...............................................
ECHO .
ECHO 1 - Recostar PDF to Tif conversion
ECHO 2 - Recostar Tiff to pdf conversion
ECHO 3 - Recostar HOCR
ECHO 4 - Ghostscript PDF Optimization command
ECHO 5 - ImageMagick Submenu
ECHO 6 - Tesseract HOCR Command
ECHO 7 - Zxing barcode value (only works on png files)
ECHO 8 - Enter new test file
ECHO 9 -
ECHO 0 - EXIT (closes CMD window)
ECHO .
SET /P M=Type 1, 2, 3, 4, 5, 6, 7, 8, 9, or 0 then press ENTER:
IF %M%==1 GOTO pdf2tif
IF %M%==2 GOTO t2p_menu
IF %M%==3 GOTO recoHOCR
IF %M%==4 GOTO GSOptimize
IF %M%==5 GOTO IMMenu
IF %M%==6 GOTO Tesseract
IF %M%==7 GOTO ZXing
IF %M%==8 GOTO InputDesignation
IF %M%==9 GOTO
IF %M%==0 exit /b
::IF %M%==0 GOTO :eof
:IMMenu
CLS
ECHO Welcome to the Ephesoft Command Line testing tool.
ECHO ImageMagick Submenu
ECHO .
ECHO ...............................................
ECHO PRESS the number to select your task, or # to EXIT.
ECHO ...............................................
ECHO .
ECHO 1 - TIFF to TIFF conversion
ECHO 2 - TIFF to PNG conversion (gray scale)
ECHO 3 - TIFF to PNG conversion (color thumbnail)
ECHO 4 - Colored TIFF to PDF conversion
ECHO 5 - Non-colored TIFF to PDF conversion
ECHO 6 - PDF to TIFF conversion
ECHO 7 - Main Menu
ECHO .
SET /P M=Type 1, 2, 3, 4, 5, 6, or 7 then press ENTER:
IF %M%==1 GOTO IMtiff2tiff
IF %M%==2 GOTO IMtiff2pngG
IF %M%==3 GOTO IMtiff2pngT
IF %M%==4 GOTO IMCtiff2pdf
IF %M%==5 GOTO IMNCtiff2pdf
IF %M%==6 GOTO IMpdf2tiff
IF %M%==7 GOTO MENU
cls
:InputDesignation
::CLS
ECHO Please place your input file into the c:\Test_Ephe\Input directory now.
ECHO .
ECHO .
ECHO Only after the file is placed in the input directory should you continue.
ECHO .
ECHO .
ECHO Please designate your input filename
set /p inputName=Input Filename:
if "!inputName!"=="" (
GOTO no_filename
) else (
GOTO Check_Exists
)
:no_filename
ECHO .
ECHO .
ECHO The filename that you have provided does not exist.
ECHO Please enter a filename that exists inside the c:\Test_Ephe\Input directory
Pause
GOTO InputDesignation
:Check_Exists
IF EXIST %EpheInput%\%inputName% (
GOTO :MENU
) ELSE (
ECHO .
ECHO ERROR: You must enter a valid filename. Do not include the path.
pause
GOTO InputDesignation
)
:pdf2tif
CLS
ECHO Processing %EpheInput%\%inputName%
%RECOSTAR_PATH%\saveimage.exe "%EpheInput%\%inputName%" 70 true
ECHO .
move %EpheInput%\*-00*.tif %Epheoutput%
ECHO .
ECHO Finished with Recostar PDF to tif conversion, press any key to return to menu
Pause
GOTO MENU
:tiff2pdf
CLS
%RECOSTAR_PATH%\RecostarPlugin.exe "!!.rsbatch file!!” "!!FPR.rsp!!” pdf 4 "%RECOSTAR_PATH%\RSO2-NET.707″ "%EpheInput%\%inputName%” OFF OFF OFF RECOSTAR_HOCR
ECHO .
ECHO .
ECHO Finished with Recostar tiff to PDF conversion, press any key to return to menu
Pause
GOTO MENU
:recoHOCR
CLS
%RECOSTAR_PATH%\RecostarPlugin.exe "!!.rsbatch file!!” "!!FPR.rsp!!” bd 4 "%RECOSTAR_PATH%\RSO2-NET.707″ _HOCR.xml ON OFF OFF RECOSTAR_HOCR
ECHO .
ECHO .
ECHO Finished with Recostar HOCR, press any key to return to menu
Pause
GOTO MENU
:GSOptimize
CLS
%GHOSTSCRIPT_HOME%\gswin64c.exe -q -dNODISPLAY -P- -dSAFER -dDELAYSAFER — %GHOSTSCRIPT_HOME%\..\pdfopt.ps "%EpheInput%\%inputName%" "%EpheOutput%\%inputName%"
ECHO .
ECHO .
ECHO Finished with Ghostscript PDF Optimization
ECHO .
Pause
GOTO MENU
:Tesseract
CLS
%DCMA_HOME%\native\Tesseract-OCR\TesseractConsole.exe "%EpheInput%\%inputName%" "%EpheOutput%\%inputName%" "-l eng" +"%DCMA_HOME%\native\Tesseract-OCR\hocr.txt"
ECHO .
ECHO .
ECHO Finished with Tesseract HOCR extraction, press any key to return to menu
Pause
GOTO MENU
:ZXing
CLS
rem must be png file, not tiff
java -cp zxing-1.6.0.jar;.; com.google.zxing.client.j2se.CommandLineRunner "%EpheInput%\%inputName%"
ECHO .
ECHO .
ECHO Finished with Zxing barcode extraction, press any key to return to menu
Pause
GOTO MENU
:IMtiff2tiff
CLS
%IM4JAVA_TOOLPATH%\Convert.exe -limit area 100mb "%EpheInput%\%inputName%” -compress LZW "%EpheOutput%\%inputName%-%04d.tif”
ECHO ImageMagick has processed this file successfully
Pause
GOTO MENU
:IMtiff2pngG
CLS
%IM4JAVA_TOOLPATH%\Convert.exe "%EpheInput%\%inputName%” -colorspace gray -alpha off "%EpheOutput%\%inputName%.png”
ECHO ImageMagick has processed this file successfully
Pause
GOTO MENU
:IMtiff2pngT
CLS
%IM4JAVA_TOOLPATH%\Convert.exe "%EpheInput%\%inputName%” -colorspace rgb -thumbnail 200×150 "%EpheOutput%\%inputName%_displayThumb.png”
ECHO ImageMagick has processed this file successfully
Pause
GOTO MENU
:IMCtiff2pdf
CLS
%IM4JAVA_TOOLPATH%\Convert.exe "%EpheInput%\%inputName%" -quality 100.0 -compress LZW "%EpheOutput%\%inputName%.pdf"
ECHO ImageMagick has processed this file successfully
Pause
GOTO MENU
:IMNCtiff2pdf
CLS
%IM4JAVA_TOOLPATH%\Convert.exe "%EpheInput%\%inputName%" -quality 100.0 -monochrome -compress LZW "%EpheOutput%\%inputName%.pdf"
ECHO ImageMagick has processed this file successfully
Pause
GOTO MENU
:IMpdf2tiff
CLS
%IM4JAVA_TOOLPATH%\Convert.exe -limit area 100mb "%EpheInput%\%inputName%” -compress LZW "%EpheOutput%\%inputName%-%04d.tif”
ECHO ImageMagick has processed this file successfully
Pause
GOTO MENU
:MakeTestDir
Mkdir C:\Test_Ephe
GOTO CheckInput
:MakeInputDir
Mkdir c:\Test_Ephe\Input
GOTO CheckOutput
:MakeOutputDir
Mkdir c:\Test_Ephe\Output
GOTO Variables