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

从命令行向SilkTest Workbench stw.exe传参时变量未被识别

解决Silk Test Workbench .Net脚本命令行变量未识别问题

错误原因

  1. 变量类型不匹配:你代码里的Public Test As String是普通模块级公共变量,而Silk Test Workbench的-variable参数仅支持识别**标记为测试参数(Test Parameter)**的变量,无法直接覆盖普通公共字段。
  2. 大小写敏感问题:错误提示中显示未识别小写test,需确保命令行变量名与代码中的Test(大写T)完全一致——stw.exe对变量名大小写敏感。

解决方法

方法一:将变量改为测试参数

在代码中给变量添加TestParameter属性,标记为可外部传递的测试参数:

Public Module Main
  <TestParameter> Public Test As String = "test"
 
  Public Sub Main()
    msgBox(Test)
  End Sub
End Module

修改后重新执行原命令:

stw.exe -dsn silktest -username user -password password -script Dummy -variable "Test=hello world"

方法二:手动解析命令行参数

如果不想使用测试参数,可在Main方法中直接读取并解析命令行参数:

Public Module Main
  Public Test As String = "test"
 
  Public Sub Main()
    Dim args() As String = Environment.GetCommandLineArgs()
    For Each arg As String In args
      If arg.StartsWith("Test=") Then
        Test = arg.Substring(5)
        Exit For
      End If
    Next
    msgBox(Test)
  End Sub
End Module

执行命令时直接附加参数即可:

stw.exe -dsn silktest -username user -password password -script Dummy "Test=hello world"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 20:31:04