如何在 Linux 中从 OS Process Sampler 执行 jar

How to execute jar from OS Process Sampler in Linux

如何在 Linux 中从 OS Process Sampler 执行 jar?我有以下 采样器,它在 Windows 中运行良好。如何在 Linux 中执行这个 OS Process Sampler?

Linux 相当于:

  • 命令:/bin/bash(或其他可能不同的Unix Shell
  • 工作目录:同Windows一样指定命令的工作文件夹
  • 命令参数:

    • -c - 根据 bash user manual

      -c string

      If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with [=16=].

    • 你的实际命令。如果命令包含空格或任何其他需要转义的特殊字符 - 使用 \ 符号转义它们或用 double 引号

      将命令括起来
      ""java -jar myjar.jar param1 param2""
      

请记住,在 Linux 中,文件名是 区分大小写的 ,因此从 Linux 点开始,将 Java 更改为 java认为这两个是完全不同的野兽。

示例配置:

示例输出:

查看 How to Run External Commands and Programs Locally and Remotely from JMeter 以全面了解此方法和其他方法。

使用/bin/bash 的方法对我不起作用。相反,我直接在命令中使用 java 并将其余部分传递给参数。这是屏幕截图。