728x90
C Implementation
01 | #include <stdio.h> |
02 |
03 | int main( void ) { |
04 | FILE *in; |
05 | extern FILE *popen(); |
06 | char buff[512]; |
07 |
08 | if (!(in = popen( "ls -sail" , "r" ))){ |
09 | exit (1); |
10 | } |
11 |
12 | while ( fgets (buff, sizeof (buff), in)!=NULL){ |
13 | printf ( "%s" , buff); |
14 | } |
15 | pclose(in); |
16 |
17 | } |
C++ Implementation
01 | #include <iostream> |
02 | #include <stdio.h> |
03 |
04 | using namespace std; |
05 |
06 | int main() { |
07 | FILE *in; |
08 | char buff[512]; |
09 |
10 | if (!(in = popen( "ls -sail" , "r" ))){ |
11 | return 1; |
12 | } |
13 |
14 | while ( fgets (buff, sizeof (buff), in)!=NULL){ |
15 | cout << buff; |
16 | } |
17 | pclose(in); |
18 |
19 | return 0; |
20 | } |
728x90
'프로그래밍' 카테고리의 다른 글
[ubuntu][ulimit] bash: ulimit: open files: cannot modify limit: Operation not permitted (0) | 2022.05.13 |
---|---|
[정보] C++ SIGCHLD, waitpid()에 관해서 (0) | 2021.11.26 |
linux 프로그램 실행 에러 (0) | 2013.06.24 |
strrncmp 함수 (0) | 2013.06.03 |
[CentOS] libmysqlclient.so.18: cannot open shared object file 실패 (0) | 2013.05.08 |
댓글