Powered by GeSHi

Source code for chomp.bat

(view source code of chomp.bat as plain text)

  1. @ECHO OFF
  2. :: Command line check
  3. IF "%1"=="" GOTO Syntax
  4. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  5.  
  6. :: Keep variables local
  7. SETLOCAL
  8.  
  9. :: Strip leading space added by Windows NT 4
  10. SET STRING=%*
  11. VER | FIND "Windows NT" >NUL
  12. IF NOT ERRORLEVEL 1 SET STRING=%STRING:~1%
  13.  
  14. :: Create temporary Kix script
  15. :: (Kix displays strings without carriage returns by default)
  16. (ECHO $RC=REDIRECTOUTPUT^("%%TEMP%%.\CHOMP.DAT"^)) > %TEMP%.\CHOMP.KIX
  17. (ECHO."%STRING%") >> %TEMP%.\CHOMP.KIX
  18. (ECHO $RC=REDIRECTOUTPUT^(""^)) >> %TEMP%.\CHOMP.KIX
  19. :: Call the temporary Kix script
  20. KIX32 %TEMP%.\CHOMP.KIX
  21. :: Display the temporary file created by the temporary Kix script
  22. TYPE %TEMP%.\CHOMP.DAT
  23. :: Delete the temporary files
  24. DEL %TEMP%.\CHOMP.KIX
  25. DEL %TEMP%.\CHOMP.DAT
  26.  
  27. :: Done
  28. ENDLOCAL
  29. GOTO:EOF
  30.  
  31.  
  32. :Syntax
  33. (ECHO.) 1>&2
  34. (ECHO Chomp.bat, Version 1.01 for Windows NT 4/2000) 1>&2
  35. (ECHO Displays command line parameters on screen) 1>&2
  36. (ECHO ^(on StdOut^) without a carriage return.) 1>&2
  37. (ECHO.) 1>&2
  38. (ECHO Usage:   %~n0  ^<string^>) 1>&2
  39. (ECHO.) 1>&2
  40. (ECHO Output:  ^<string^> without carriage return on StdOut) 1>&2
  41. (ECHO.) 1>&2
  42. (ECHO Remarks: [1] ^<string^> should NOT contain any double quotes!) 1>&2
  43. (ECHO          [2] Windows 2000 will strip leading spaces from ^<string^>) 1>&2
  44. (ECHO          [3] This batch file uses Kix, make sure it is installed) 1>&2
  45. (ECHO              and that KIX32.EXE can be found in the PATH) 1>&2
  46. (ECHO.) 1>&2
  47. (ECHO Example: ^> SETDATE.BAT ECHO @ECHO OFF) 1>&2
  48. (ECHO          ^>^>SETDATE.BAT CALL %~nx0 SET DATE=) 1>&2
  49. (ECHO          ^>^>SETDATE.BAT DATE/T) 1>&2
  50. (ECHO          CALL SETDATE.BAT) 1>&2
  51. (ECHO          SET DATE) 1>&2
  52. (ECHO will display:) 1>&2
  53. FOR /F "tokens=*" %%A IN ('DATE/T') DO (ECHO          DATE=%%A) 1>&2
  54. (ECHO.) 1>&2
  55. (ECHO Written by Rob van der Woude) 1>&2
  56. (ECHO http://www.robvanderwoude.com) 1>&2
  57.