【问题标题】:Converting Shell Script to Batch for Sipp将 Shell 脚本转换为 Sipp 的批处理
【发布时间】:2013-11-27 09:01:02
【问题描述】:

这是用于记录 sipp 输出的 shell 脚本,如网站 http://sipp.sourceforge.net/doc/faq.html 所示

我以前从未编写过批处理脚本,我很难理解如何转换此代码以使其在 Windows 中运行。

 cat run.sh
#!/bin/sh
>results.txt
for i in $*
do
  echo Launching test $i >> results.txt
  ./sipp -sf $i -m 1 127.0.0.1
  if test $? -ne 0
    then
        echo Test $i failed >> results.txt
    else
        echo Test $i succeeded >> results.txt
    fi
done
exit 0

有人可以帮助我吗?此外,for 循环中的 $* 表示什么? 我批量尝试了 if 条件IF %test NEQ 0 的等效项,但出现语法错误。

【问题讨论】:

  • 我可能应该在输入答案之前先输入评论 - 但如果您能准确说明您卡在哪些部分以及您尝试了什么,您可能会得到更好的帮助。

标签: shell batch-file sip


【解决方案1】:

对于“直接翻译”而不是“防弹”代码,您可以尝试

@echo off
    setlocal enableextensions

    for %%i in (%*) do (
        echo Launching test %%i >> results.tx
        .\sipp -sf %%i -m 1 127.0.0.1
        if errorlevel 1 (
            echo Test %%i failed >> results.txt
        ) else (
            echo Test %%i failed >> results.txt
        )
    )

    exit /b 0

不确定它是否适合 sipp,我从未使用过,但这是基本思想

【讨论】:

    【解决方案2】:

    $* 将所有输入参数作为一个单词返回给您。

    另外,据我所知,BAT 中不存在“测试”。如果你想检查退出代码,你可以使用ERRORLEVEL 之类的东西(检查类似的问题https://superuser.com/questions/194662/how-to-check-the-exit-code-of-the-last-command-in-batch-file

    您要做的是,了解 shell-script 逻辑,然后使用参考站点(例如 http://ss64.com/nt/)来移植代码(同时请记住,它可能不是纯粹的一对一端口)。

    另外,有几个想法:

    • 不确定您是否有可用的 SIPP 的 Windows 端口。可能想检查一下。
    • 考虑开始使用 Powershell。它肯定比 BAT 更通用。如果您有 bash 背景,可能会更容易切换到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多