---
title: C++
slug: brcli-cpp
docTags: 
createdAt: 2023-03-08T03:27:43.000Z
---

:::CodeblockTabs
```cpp
#include <iostream>
#include <string>
#include <memory>

std::string exec(const char* cmd) {
    std::array<char, 128> buffer;
    std::string result;
    std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
    if (!pipe) {
        return "popen() failed!";
    }
    while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
        result += buffer.data();
    }
    return result;
}

int main(int argc, char *argv[]) {
		std::string cargs[] = {
			"./BarcodeReaderCLI",
			"-type=code128",
			"https://wabr.inliteresearch.com/SampleImages/1d.pdf",
			"@./brcli-example.config"};// Additional options and sources in configuration file
		for (int i = 0; i < sizeof(cargs)/sizeof(cargs[0]); i++)
			cmd += cargs[i] + " ";
	}
	std::string out = exec(cmd.c_str());
    std::cout << out << std::endl;
    return 0;
}
```

brcli-example.config

```linux
# -silent
-type=code39
# image from URL
https://wabr.inliteresearch.com/SampleImages/1d.pdf
# image from local folder
./images/test.tif
```
:::

