system 함수에서 에러났을때
글쓴이: 베리스타 / 작성시간: 목, 2003/11/13 - 6:19오후
system함수를 사용할때 에러 나면 무조건 255가 echo되는데,
errno를 정확히 알 수 있을까요?
예를 들어 cp명령을 system함수를 이용해서 한다면, dest permission에러인지 souce파일이 없는지 그런 종류의 에러넘버를 알고 싶은데, 그 에러 번호좀 알 수 있다면 알려주세요^^;
ex ) Permission denied = 1
No such file or directory = 2
이런식으로 에러 뜨는...^^;
그럼 수고들 하세요~
Forums:
errno 를 넣어서 출력해 보세요.자세한건 man errno 해
errno 를 넣어서 출력해 보세요.
자세한건 man errno 해보시구요.
/usr/include/asm/errno.h 에 반환값이 좍
정의되어 있습니다.
에러 넘버 안납니다.
제가 말씀 드렸는데요.
에러 넘버가 무조건 256이고 실패해도 성공 떨어집니다.
-_-;;참으로 난감하지 않을수가 없어요
위 문장이 destination이 쓰기 권한 없는곳으로 이동했을때 에러가 퍼미션에러라는 정확한 에러넘버가 떨어져야 하는데, i값은 256떨어지고, errno는 0떨어지고, strerror(errno)는 Success떨어지고, 명령어뒤에 echo $? 를 붙이면 255가 떨어집니다.
각각 제 멋대로 떨어집니다.-_-;;퍼미션 에러가 전혀 안나오는거죠.
혹시 해결책 아시는분 게시나여?
하이요^^
혹시,,
myCmd가 &로 끝나는지는 않습니까?
system은 /bin/sh -c "myCmd" 인데,
&로 끝나면 subshell 생성이 되기만 하면 0을 return 하지요..
저라면 popen()을 쓰겠습니다.
system()으로 외부 실행 파일을 이용하였을 때는 그 결과값등을 처리하기가 힘들죠.
그래서 저는 popen을 주로 씁니다.
안그렇다면 다른 테크닉을 써야되는데 제가 아는 방법은 지저분한 방법 밖에 없어서..-_-;
A few Good Man
댓글 달기