Is there any analogue of the PHP system in C?
man systemsays it systemreturns the status of the command, but I need the output (as in PHP).
man system
system
Of course, I can use pipes for this, but is there a standard way?
You can use popen and a related function like:
// command to be run. char *cmd = "date"; // open pipe stream. FILE *fp = popen(cmd,"r"); int ch; // error checking. if(!fp) { fprintf(stderr,"Error popen with %s\n",cmd); exit(1); } // read from the process and print. while((ch = fgetc(fp)) != EOF) { putchar(ch); } // close the stream. pclose(fp);
Perfect link
If you need the output of a command, you should use it popen()on Unix (with "r" to indicate what you want to read from the command).
popen()
FILE *fp = popen("some -convoluted command", "r"); ...check for validity... ...read data from command... pclose(fp);
Source: https://habr.com/ru/post/1777900/More articles:How to replace part of a string with special characters - javajpGraph alternative - phpProblem using dynamically added html object from javascript - javascriptmax mysql queries per minute - performanceThe most reliable way to clear the list depending on Predicate - listSelect identifiers from an array of jquery elements - jqueryHow to deploy an ad-hoc distribution (ipa file) or how to sync iTunes with devices - synchronizationFixed position in mobile browser for footer - javascriptIs there any library popular in Python for monitoring a Linux / Unix system? - pythonДополнительные темы - jquery-uiAll Articles