esnet / esnet/iperf

Silence stdout but still get JSON output via API

Open
#1,214 2 comments 0 reactions 1 assignee Claimed by @bmah888 View on GitHub
Dominant language
C
Stars
8.8k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

# Context

* Version of iperf3:
```
iperf 3.9 (cJSON 1.7.13)
Linux localhost 5.13.19-200.fc34.x86_64 #1 SMP Sat Sep 18 16:32:24 UTC 2021 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, SCTP, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing, authentication
```
* Hardware:
x86_64

* Operating system (and distribution, if any):
GNU/Linux, Fedora 34

* Other relevant information (for example, non-default compilers,
libraries, cross-compiling, etc.):

# Bug Report

* Expected Behavior
I want to silcence output via stdout, but still get JSON output via `iperf_get_test_json_output_string()` API call. Silencing was done via `iperf_set_test_logfile("/dev/null")`.

* Actual Behavior
If output is being silenced, the `iperf_get_test_json_output_string()` API call returns NULL

* Steps to Reproduce
```
//C++
test_ = iperf_new_test();
iperf_set_test_json_output(test_, 1);
iperf_set_test_logfile("/dev/null");
[...]
int rc = iperf_run_client(test_);
[...]
auto res = iperf_get_test_json_output_string(test_);
if (res == nullptr)
{
throw std::runtime_error("Iperf3: empty result");
}
```
will throw the exception.

* Possible Workaround
```
test_ = iperf_new_test();
iperf_set_test_json_output(test_, 1);
output_file_ = std::tmpnam(nullptr);
iperf_set_test_logfile(output_file_);
[...]
int rc = iperf_run_client(test_);
[...]
[open and read JSON from file output_file_]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.