Languages: [EN] English | [KO] 한국어
Simple Windows Batch Script Library
간단한 배치스크립트 라이브러리
Overview
소개
Base script to convert the constraints of a batch script into a runtime structure..
배치스크립트의 제약적 환경을 런타임 구조로 바꾸기 위한 기반 스크립트.
Why Batch Scripts?
- One of the reasons for still using batch scripts is their fast execution.
- They are simple and natively built into Windows, allowing execution even in restricted security environments.
Issues
- One of the major issues is the limited functionality provided by batch scripts.
- Specifically, problems arise when managing common code (libraries).
- I looked for it but couldn't find the feature I need
Solution
- Building a custom implementation.
Implementation Details
- Dynamic Module Merging
- Duplicate Loading Prevention
- Automatic Cleanup After Merged Execution
- Automatic Deletion of Generated Merged Batch Files After Completion
- Retention of Merged Files Upon Execution Error (for Debugging)
- Argument Passing Support
- File Existence Verification
- Standalone Execution and Chaining Support
- Architectural Design to Minimize Mutual Interference Between Modules
How to Use
- 'Test' refers to the name of the script file itself.
- 'lib' refers to the common code to be imported.
- If an error occurs during execution, a script with the recorded execution time remains, making debugging easy.
Tip
This library allows you to write code in a way similar to modern programming languages, including modularity, reusability, and argument passing, even in common batch scripts
A complete framework based on this code has already been developed.
왜 배치 스크립트인가?
- 여전히 배치 스크립트를 사용하는 이유 중 하나는 실행이 빠르고
- 간단하며 윈도우에 이미 내장된 상태라 보안 환경에서도 실행 가능
문제점
- 큰 문제중 하나는 배치 스크립트의 제공 기능이 매우 제한됨
- 특히 공통 코드 관리에 문제가 발생
- 찾아보았지만 필요한 기능이 없음
해결
- 직접 만들기
- 배치 환경에서 동적 링커/로더 구현
구현 내용
- 동적 모듈 병합
- 중복 로딩 방지
- 병합 실행 후 자동 정리
- 실행 종료 후 생성된 병합 배치 파일 자동 삭제
- 실행 오류시 병합 파일 남김
- 인자 전달 지원
- 파일 존재 검사
- 독립 실행 및 체이닝
- 각 모듈이 서로 영향을 최소화하도록 구조 설계
사용 방법
- Test 는 해당 스크립트 파일명
- lib 는 공통적으로 불러올 코드
- 스크립트 수행 도중 오류 발생시 실행 시간이 기록된 스크립트가 남아 디버깅이 간단
참고 사항
이 라이브러리를 이용하면 일반적인 배치 스크립트에서도 모듈화, 재사용성, 인자 전달 등 현대적 프로그래밍 언어와 유사한 방식으로 코드 작성 가능
이미 해당 코드를 기반으로 프레임워크 제작 완료
::================================================================================
::##
::## this code written by http://project-ap.blogspot.com/
::##
::## Copyright (C) 2017-2023 http://project-ap.blogspot.com/
::##
::## This program is free software: you can redistribute it and/or modify
::## it under the terms of the GNU General Public License as published by
::## the Free Software Foundation, version 3 of the License.
::##
::## For more information and updates, please visit the blog address above.
::================================================================================
::$@test.cmd #0.001
@echo off
::$Import
call :Import "Test" "lib" %*
::$Code
goto :EOF
::$Define
if not defined Loaded_%TempCacheName% (
:Import
set "TempCacheName=%~1"
for /f "tokens=2 delims==." %%a in ('wmic OS Get localdatetime /value') do set _rand=%%a"
if not defined Loaded_%TempCacheName% (
for %%a in (%~2) do (
if not exist "%%a.cmd" (
echo %%a File Not Found.
pause
exit
)
)
set Loaded_%TempCacheName%=y
type %~f0 > _Cache_%TempCacheName%_%_rand%.cmd
for %%a in (%~2) do (type %%a.cmd >> _Cache_%TempCacheName%_%_rand%.cmd)
_Cache_%TempCacheName%_%_rand%.cmd %3 %4 %5 %6 %7 %8 %9
del _Cache_%TempCacheName%_%_rand%.cmd
set Loaded_%TempCacheName%=
set TempCacheName=
set _rand=
goto :EOF
)
goto :EOF
)
goto :EOF
::$Library
Comments
Post a Comment