system 함수에서 에러났을때

베리스타의 이미지

system함수를 사용할때 에러 나면 무조건 255가 echo되는데,

errno를 정확히 알 수 있을까요?

예를 들어 cp명령을 system함수를 이용해서 한다면, dest permission에러인지 souce파일이 없는지 그런 종류의 에러넘버를 알고 싶은데, 그 에러 번호좀 알 수 있다면 알려주세요^^;

ex ) Permission denied = 1
No such file or directory = 2

이런식으로 에러 뜨는...^^;

그럼 수고들 하세요~

xfree의 이미지

errno 를 넣어서 출력해 보세요.

자세한건 man errno 해보시구요.

/usr/include/asm/errno.h 에 반환값이 좍
정의되어 있습니다.

베리스타의 이미지

제가 말씀 드렸는데요.

에러 넘버가 무조건 256이고 실패해도 성공 떨어집니다.

-_-;;참으로 난감하지 않을수가 없어요

if(i = system(myCmd))
	{
		md_printf(MD_DEBUG_FILE_COPY, "i=%d\n", i);
		md_printf(MD_DEBUG_FILE_COPY, "Error(%d):%s\n", errno, strerror(errno));
		md_printf(MD_DEBUG_FILE_COPY, "cp error!\n");
		return AR_ERROR;
	}

위 문장이 destination이 쓰기 권한 없는곳으로 이동했을때 에러가 퍼미션에러라는 정확한 에러넘버가 떨어져야 하는데, i값은 256떨어지고, errno는 0떨어지고, strerror(errno)는 Success떨어지고, 명령어뒤에 echo $? 를 붙이면 255가 떨어집니다.

각각 제 멋대로 떨어집니다.-_-;;퍼미션 에러가 전혀 안나오는거죠.

혹시 해결책 아시는분 게시나여?

하이요^^

june8th의 이미지

myCmd가 &로 끝나는지는 않습니까?

system은 /bin/sh -c "myCmd" 인데,
&로 끝나면 subshell 생성이 되기만 하면 0을 return 하지요..

코퍼스의 이미지

system()으로 외부 실행 파일을 이용하였을 때는 그 결과값등을 처리하기가 힘들죠.
그래서 저는 popen을 주로 씁니다.

안그렇다면 다른 테크닉을 써야되는데 제가 아는 방법은 지저분한 방법 밖에 없어서..-_-;

A few Good Man

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.