change all cn to en to avoid annoying errors
This commit is contained in:
@@ -3,36 +3,36 @@ param(
|
||||
[string]$WorkDir = $null
|
||||
)
|
||||
|
||||
# 1. 处理工作目录
|
||||
# 1. Resolve work directory.
|
||||
if ([string]::IsNullOrEmpty($WorkDir)) {
|
||||
$WorkDir = $PSScriptRoot
|
||||
} else {
|
||||
# 如果 WorkDir 里包含变量(如 $env:APPDATA),展开它
|
||||
# Expand variables in WorkDir, such as $env:APPDATA.
|
||||
$WorkDir = $ExecutionContext.InvokeCommand.ExpandString($WorkDir)
|
||||
}
|
||||
|
||||
# 确保目录存在,否则命令会报错
|
||||
# Make sure the directory exists.
|
||||
if (-not (Test-Path $WorkDir)) {
|
||||
Write-Warning "`n[CMD] WARNING: The work dir does not exist, using ($WorkDir)"
|
||||
$WorkDir = $PSScriptRoot
|
||||
}
|
||||
|
||||
# 2. 处理命令中的环境变量
|
||||
# 2. Expand variables in the command.
|
||||
$ProjectRoot = Split-Path $PSScriptRoot -Parent
|
||||
# === 替换 $PSScriptRoot 为实际的绝对路径 ===
|
||||
# 注意:要处理反斜杠转义问题,直接用字符串替换最安全
|
||||
# Replace $PSScriptRoot with the project root path.
|
||||
# Direct string replacement is the safest option for backslashes.
|
||||
if ($Command.Contains('$PSScriptRoot')) {
|
||||
$Command = $Command.Replace('$PSScriptRoot', $ProjectRoot)
|
||||
}
|
||||
|
||||
# 这一步很关键,让你可以写 "echo $env:USERNAME"
|
||||
# This allows commands such as "echo $env:USERNAME".
|
||||
$Command = $ExecutionContext.InvokeCommand.ExpandString($Command)
|
||||
|
||||
Write-Host "`n[CMD] Execute: $Command" -ForegroundColor Gray
|
||||
|
||||
# 3. 启动进程
|
||||
# /c 表示执行完命令后关闭 cmd 窗口
|
||||
# /s 开启参数的一般处理(忽略第一个和最后一个引号,为了兼容复杂引号情况)
|
||||
# 3. Start cmd.exe.
|
||||
# /c closes cmd after the command completes.
|
||||
# /s enables cmd quote handling for complex command strings.
|
||||
$processOptions = @{
|
||||
FilePath = "cmd.exe"
|
||||
ArgumentList = "/s", "/c", "`"$Command`""
|
||||
@@ -45,10 +45,10 @@ $processOptions = @{
|
||||
try {
|
||||
$proc = Start-Process @processOptions
|
||||
|
||||
# 4. 检查退出代码 (ExitCode)
|
||||
# 4. Check exit code.
|
||||
if ($proc.ExitCode -ne 0) {
|
||||
Write-Error "`n[CMD] Failed to execute, exit code: $($proc.ExitCode)"
|
||||
}
|
||||
} catch {
|
||||
Write-Error "`n[CMD] Failed to start process: $_"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user