Skip to content

Instantly share code, notes, and snippets.

@wbzyl
Created October 23, 2011 13:30
Show Gist options
  • Save wbzyl/1307361 to your computer and use it in GitHub Desktop.
Save wbzyl/1307361 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
/* wykorzystanie powłoki sh do wywołania programów:
popen, system, pclose */
/* obie funkcje powinny być zadeklarowane w stdio.h (a nie są?) */
FILE *popen(const char *, const char *);
int pclose(FILE *);
int main() {
FILE *fp;
char string[1024];
/* wywołanie polecenia */
system("date");
/* wywołanie polecenia i przechwycenie jego wyników */
fp = popen("date", "r"); /* r = odczyt */
if (fp==NULL)
fprintf(stderr,"! nie można uruchomić polecenia date\n");
else {
fgets(string,1024,fp);
printf("Wynik wykonania polecenia date: [%s]\n",string);
pclose(fp);
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment