Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Este exemplo usa o comando popen que permite correr comandos de terminal. Neste caso, lista a directoria (ls -l) */
- // Apple Xcode
- #include <stdio.h>
- #include <stdlib.h>
- #define PATH_MAX 500
- int main (int argc, const char * argv[])
- {
- // linha de comandos
- FILE *the_file;
- int the_status;
- char the_path[PATH_MAX];
- // initiate pipe streams to or from a process
- the_file = popen("ls -l", "r");
- if (the_file == NULL)
- {
- printf("erro no comando");
- }
- // output
- while (fgets(the_path, PATH_MAX, the_file) != NULL)
- {
- printf("%s", the_path);
- }
- // status
- the_status = pclose(the_file);
- if (the_status == -1)
- {
- // error reported by pclose()
- printf("close");
- }
- else
- {
- /* Use macros described under wait() to inspect `status' in order
- to determine success/failure of command executed by popen() */
- printf("%i\n", the_status);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement