You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telosys 4.2.0无-c命令,如何通过PowerShell脚本执行Telosys命令?

Telosys 4.2.0 无 -c 参数时,如何通过PowerShell脚本执行批量命令

我写了个generate.ps1脚本,用来把JSON转成.entity文件,之后自动执行Telosys的gen命令。但Telosys 4.2.0版本不支持-c参数,试了三种执行方式,结果都直接进入交互模式(-h .参数有效,只有-c无效),而且官方文档里根本没提这个参数。想问下有没有办法让generate.ps1正常执行Telosys命令?

原generate.ps1脚本

param (
    [string]$JsonPath = "Model-Json\*.json",
    [string]$ModelFolder = "TelosysTools\models\product-model"
)

# Convert all matching JSONs to .entity files
$entities = Get-ChildItem $JsonPath | ForEach-Object {
    .\Convert-JsonToEntity.ps1 -JsonPath $_.FullName -ModelFolder $ModelFolder
    [System.IO.Path]::GetFileNameWithoutExtension($_.FullName)
}

# Build gen command for all converted entities
$genArgs = "gen " + ($entities -join " ") + " * -ifnew"
if (-not $entities) {
    Write-Host "No entities to generate."
    exit 0
}

# Run Telosys generation with full path
$command = "m $(Split-Path $ModelFolder -Leaf);b csharp-bundle;$genArgs;q"
cmd.exe /c "D:\setups\telosys-cli-4.2.0-001\tt.bat -h . -c `"$command`""

# Show results
dir Controllers,Models,Services,Repositories,UnitOfWork -File -Recurse

尝试过的三种执行方式

# 方式1
$telosysPath = "D:\setups\telosys-cli-4.2.0-001\tt.bat"
$command = "& '$telosysPath' -h . -c `"m $(Split-Path $ModelFolder -Leaf);b csharp-bundle;$genArgs;q`""
Invoke-Expression $command

# 方式2
$telosysPath = "D:\setups\telosys-cli-4.2.0-001\tt.bat"
$command = "m $(Split-Path $ModelFolder -Leaf);b csharp-bundle;$genArgs;q"
Write-Host "Running: $telosysPath -h . -c `"$command`""
cmd.exe /c "$telosysPath -h . -c `"$command`""

# 方式3
$command = "m $(Split-Path $ModelFolder -Leaf);b csharp-bundle;$genArgs;q"
cmd.exe /c "D:\setups\telosys-cli-4.2.0-001\tt.bat -h . -c `"$command`""

可行解决方案:用命令文件重定向执行

Telosys 4.x系列(包括4.2.0)确实移除了-c参数,但支持从标准输入读取命令序列。可以把要执行的命令写入临时文本文件,再通过输入重定向让tt.bat读取执行。修改脚本中的Telosys执行部分即可:

# 构建命令序列,每行一个命令
$commands = @(
    "m $(Split-Path $ModelFolder -Leaf)",
    "b csharp-bundle",
    $genArgs,
    "q"
)

# 将命令写入临时文件(用ASCII编码确保Telosys能正确解析)
$tempCmdFile = Join-Path $env:TEMP "telosys_commands.txt"
$commands | Out-File -FilePath $tempCmdFile -Encoding ASCII

# 执行Telosys,通过输入重定向读取命令文件
$telosysPath = "D:\setups\telosys-cli-4.2.0-001\tt.bat"
cmd.exe /c "$telosysPath -h . < `"$tempCmdFile`""

# 清理临时文件
Remove-Item $tempCmdFile -Force

关键说明

  1. 把每个Telosys命令单独拆分到一行,避免分号分隔可能引发的解析问题
  2. 使用ASCII编码写入临时文件,匹配Telosys CLI的输入编码要求
  3. 执行完成后自动删除临时文件,避免冗余文件残留

内容的提问来源于stack exchange,提问作者saibin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 15:42:36