fork download
  1. #include <stdio.h> /* printf */
  2. #include <stdlib.h> /* system, NULL, EXIT_FAILURE */
  3.  
  4. void write_data (FILE * stream)
  5. {
  6. int i;
  7. for (i = 0; i < 100; i++)
  8. fprintf (stream, "%d\n", i);
  9. if (ferror (stream))
  10. {
  11. fprintf (stderr, "Output to stream failed.\n");
  12. exit (EXIT_FAILURE);
  13. }
  14. }
  15.  
  16.  
  17. int main ()
  18. {
  19. FILE *output;
  20. char* pPath;
  21.  
  22. output = popen("uname -a", "w");
  23. write_data (output);
  24. printf("\n\n");
  25. output = popen ("ls", "w");
  26. write_data (output);
  27. printf("\n\n");
  28. output = popen ("cat /etc/passwd", "w");
  29. write_data (output);
  30. printf("\n\n");
  31. pPath = getenv ("PATH");
  32. if (pPath!=NULL)
  33. printf ("$PATH: %s\n",pPath);
  34. pPath = getenv ("HOME");
  35. if (pPath!=NULL)
  36. printf ("$HOME: %s\n",pPath);
  37. pPath = getenv ("HOST");
  38. if (pPath!=NULL)
  39. printf ("$HOST: %s\n",pPath);
  40. pPath = getenv ("SHELL");
  41. if (pPath!=NULL)
  42. printf ("$SHELL: %s\n",pPath);
  43. pPath = getenv ("REMOTEHOST");
  44. if (pPath!=NULL)
  45. printf ("$REMOTEHOST: %s\n",pPath);
  46. return 0;
  47. }
Success #stdin #stdout 0s 2196KB
stdin
Standard input is empty
stdout




$PATH: /usr/local/bin:/usr/bin:/bin
$HOME: /home/EVhqWX