Advertisement
jcunews

cscript2.bat

Jan 24th, 2022
1,882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.41 KB | None | 0 0
  1. @echo off
  2. setlocal
  3. if "%~1" neq "" goto go
  4.  
  5. :help
  6. echo CScript2. https://pastebin.com/u/jcunews
  7. echo.
  8. echo Wrapper batch file for CSCRIPT to make it auto search script file in PATH
  9. echo environment variable.
  10. echo.
  11. echo For example, if `myscript.vbs` is designed for console use, and its path is
  12. echo already in the PATH environment variable, by default, Windows will run it
  13. echo using the GUI (less) version of Windows Scripting Host's WSCRIPT. Normally,
  14. echo when the script's path is not the current directory, the full path of the
  15. echo script must be specified e.g.: `cscript "d:\my tools\myscript.vbs"`.
  16. echo This batch file eliminates the need to specify the full path of the script
  17. echo so it would only need to be: `cscript2 myscript.vbs`.
  18. echo.
  19. echo Usage: cscript2 [cscript options...] {script file} [script args...]
  20. echo.
  21. echo `prm_` environment variable will contain CSCRIPT's command line tail.
  22. exit/b 1
  23.  
  24. :go
  25. set prm_=
  26. set sf_=
  27. set fl_=0
  28.  
  29. :doprm
  30. set "ar_=%~1"
  31. if "%ar_:~0,1%" neq "/" (
  32.   if %fl_% == 0 (
  33.     call :chk "%~1"
  34.     if errorlevel 1 exit/b 1
  35.   ) else set "prm_=%prm_% %1"
  36. ) else set "prm_=%prm_% %1"
  37. shift
  38. if "%~1" neq "" goto doprm
  39. if %fl_% == 0 goto help
  40. set ar_=
  41. set fl_=
  42. cscript.exe%prm_%
  43. exit/b %errorlevel%
  44.  
  45. :chk
  46. set fl_=1
  47. for %%A in (%1) do set "sf_=%%~$path:A"
  48. if "%sf_%" == "" (
  49.   echo Can not find script file %1.
  50.   exit/b 1
  51. )
  52. set "prm_=%prm_% %sf_%"
  53. set sf_=
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement