Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal
- if "%~1" neq "" goto go
- :help
- echo CScript2. https://pastebin.com/u/jcunews
- echo.
- echo Wrapper batch file for CSCRIPT to make it auto search script file in PATH
- echo environment variable.
- echo.
- echo For example, if `myscript.vbs` is designed for console use, and its path is
- echo already in the PATH environment variable, by default, Windows will run it
- echo using the GUI (less) version of Windows Scripting Host's WSCRIPT. Normally,
- echo when the script's path is not the current directory, the full path of the
- echo script must be specified e.g.: `cscript "d:\my tools\myscript.vbs"`.
- echo This batch file eliminates the need to specify the full path of the script
- echo so it would only need to be: `cscript2 myscript.vbs`.
- echo.
- echo Usage: cscript2 [cscript options...] {script file} [script args...]
- echo.
- echo `prm_` environment variable will contain CSCRIPT's command line tail.
- exit/b 1
- :go
- set prm_=
- set sf_=
- set fl_=0
- :doprm
- set "ar_=%~1"
- if "%ar_:~0,1%" neq "/" (
- if %fl_% == 0 (
- call :chk "%~1"
- if errorlevel 1 exit/b 1
- ) else set "prm_=%prm_% %1"
- ) else set "prm_=%prm_% %1"
- shift
- if "%~1" neq "" goto doprm
- if %fl_% == 0 goto help
- set ar_=
- set fl_=
- cscript.exe%prm_%
- exit/b %errorlevel%
- :chk
- set fl_=1
- for %%A in (%1) do set "sf_=%%~$path:A"
- if "%sf_%" == "" (
- echo Can not find script file %1.
- exit/b 1
- )
- set "prm_=%prm_% %sf_%"
- set sf_=
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement