linux - 如何使 Jmeter 从 CMD 运行命令 - 操作系统采样器 - JMETER

标签 linux jmeter

我正在努力使用 jmeter 将 cmd 命令运行到远程桌面。 我使用操作系统采样器。 我有一个命令,如果我从计算机的命令行运行它,它就可以工作,但是当我尝试让 jmeter 运行它时,它失败了——我使用同一台计算机。 命令是:

plink -ssh jenkins@178.27.288.288 -pw passtest  sudo /opt/test/test.sh

我添加了一个操作系统采样器,如下所示: enter image description here

工作目录是cmd.exe目录。 该命令是我希望 jmeter 运行的完整命令,与直接在 cmd 上完美运行的命令相同。

我收到这个错误:

Response message: Exception occurred whilst executing system call: java.io.IOException: Cannot run program "plink -ssh jenkins@178.27.288.288 -pw passtest  sudo /opt/test/test.sh" (in directory "c:\windows\system32"): CreateProcess error=2, The system cannot find the file specified

我不知道 jmeter 想要哪个文件,我只是想让他运行命令,连接到远程计算机并运行命令,该命令在命令行中完美运行并在远程计算机中运行脚本。

我在网上找到了这个博客: https://www.blazemeter.com/blog/how-run-external-commands-and-programs-locally-and-remotely-jmeter

虽然说可以做到,但由于很容易,所以他们没有显示分步说明。

当我将命令更改为 dir 时,它运行正常,结果就像我在命令行中编写 dir 一样。

如何让 jmeter 打开命令行,只输入命令并按回车,并显示结果?

最佳答案

在命令中,您需要给出要执行的程序的名称。在命令提示符的情况下它是 cmd.exe 而对于 shell 我认为它是 powershell.exe 其余部分需要作为命令参数传递。

检查下面的命令参数:-

The OS Process Sampler is a sampler that can be used to execute commands on the local machine. It should allow execution of any command that can be run from the command line. Validation of the return code can be enabled, and the expected return code can be specified. Note that OS shells generally provide command-line parsing. This varies between OSes, but generally the shell will split parameters on white-space. Some shells expand wild-card file names; some don't. The quoting mechanism also varies between OSes. The sampler deliberately does not do any parsing or quote handling. The command and its parameters must be provided in the form expected by the executable. This means that the sampler settings will not be portable between OSes.

Many OSes have some built-in commands which are not provided as separate executables. For example the Windows DIR command is part of the command interpreter (CMD.EXE). These built-ins cannot be run as independent programs, but have to be provided as arguments to the appropriate command interpreter.

For example, the Windows command-line: DIR C:\TEMP needs to be specified as follows:

Command: CMD Param 1: /C Param 2: DIR Param 3: C:\TEMP

如果命令是远程命令,请尝试使用“远程命令:Linux/MacOSX”和您共享的博客中显示的 SSH 采样器。

下面是简单执行 dir 命令的截图:-

enter image description here enter image description here

--更新-- 额外的截图

要执行 Windows 命令 DIR c:\test 使用以下设置

enter image description here

关于linux - 如何使 Jmeter 从 CMD 运行命令 - 操作系统采样器 - JMETER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51314622/

相关文章:

java - 在主机 : '/' 中发现 jmeter 非法字符

java - jmeter 性能测试 : using the functions

c - 我如何获得 linux 内核服务中断所花费的时间

linux - 如何防止 Linux 虚拟机在 VMWare 上关闭/注销?

linux - 在目录中搜索文本文件并向每个文件附加一个(静态)行

jmeter - JMeter上载具有jmx文件相对路径的文件

linux - scp 不返回错误也不复制

python - 设置环境变量,使其可以在我的程序之外读取

java - 在 JMeter 的 BeanShell 采样器中将字符串解析为整数

xml - Jmeter - 生成 xml