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

如何显示或捕获SSHLibrary中"Execute command"的完整输出及SSH命令执行问题

SSH Automation & Capturing Full Command Output with SSHLibrary

Got it, let's break down how to solve your SSH tasks and capture the full output from Execute Command in Robot Framework's SSHLibrary.

1. Complete SSH Connection & Command Execution Script

First, here's a clean, working script that follows your requirements—we'll handle connecting to your target IP, logging in, and running the ./send command in the specified directory.

Option 1: Switch to Target Directory First (Explicit Path Handling)

This approach makes it clear you're working in the /export/home/IKBAL/Simulator directory:

*** Settings ***
Library    SSHLibrary

*** Variables ***
${SSH_IP}    125.230.200.80
${USERNAME}    your_username_here
${PASSWORD}    your_password_here

*** Test Cases ***
Run Send Command on Remote Server
    Close All Connections
    Open Connection    ${SSH_IP}    port=22    timeout=10
    Login    ${USERNAME}    ${PASSWORD}    delay=10 seconds
    # Execute command in the target directory using && to chain commands
    ${command_output}=    Execute Command    cd /export/home/IKBAL/Simulator && ./send 1 1 hostsocket S
    # Log the output (we'll cover this more in section 2)
    Log    Command Output: ${command_output}    INFO
    Close All Connections

Option 2: Use Absolute Path for the Command

If you prefer to skip switching directories, you can run the command directly with its full path:

# Replace the Execute Command line above with this:
${command_output}=    Execute Command    /export/home/IKBAL/Simulator/send 1 1 hostsocket S

2. Capturing & Displaying Full Execute Command Output

SSHLibrary's Execute Command returns the standard output (stdout) of the command by default. To capture and view the full output (including stderr if needed), follow these tips:

Capture Stdout Only (Default Behavior)

Assign the keyword's return value to a variable, then log it to the Robot Framework report or console:

# Capture output to a variable
${stdout}=    Execute Command    cd /export/home/IKBAL/Simulator && ./send 1 1 hostsocket S
# Log to the test report (INFO level ensures it's visible)
Log    Full Stdout Output: ${stdout}    INFO
# Print directly to the console (useful for real-time debugging)
Log To Console    ${stdout}

Capture Both Stdout & Stderr

If your command might produce error output (stderr), use the return_stderr=True parameter to capture both streams:

${stdout}=    ${stderr}=    Execute Command    cd /export/home/IKBAL/Simulator && ./send 1 1 hostsocket S    return_stderr=True
Log    Stdout: ${stdout}    INFO
Log    Stderr: ${stderr}    INFO
# If you want to combine both streams into one variable
${full_output}=    Catenate    SEPARATOR=\n    ${stdout}    ${stderr}
Log    Full Output (Stdout + Stderr): ${full_output}    INFO

Ensure Long Output Isn't Truncated

By default, Robot Framework might truncate long logs. To see the full output, set the log level to DEBUG at the start of your test case:

Set Log Level    DEBUG

This ensures even lengthy output is fully recorded in the test report.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:29:16