Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

How to get result from system command execution

What is the function like system() that return the result of execution instead of printing the result on the terminal.

ex:

result = system("/usr/local/md5 1234");

I want to get the result of the md5 command, not a return status.

Thank you for you help
0
mrbird
Asked:
mrbird
1 Solution
 
MFCRichCommented:
FILE *popen(const char *command, const char *type)

See man popen

'type' is determines if the FILE is open for reading or writing just like the fopen function.

> FILE *fp = popen("/usr/local/md5 1234", "r");
> # Now read from fp

0
 
mrbirdAuthor Commented:
Thank you
It works now.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now