따옴표가 들어갈때만 안되네요.

jagalchee의 이미지

리눅스에서 간단한 서버-클라이언트 소켓 프로그래밍을 하고 있습니다.
클라이언트에서 영어 단어를 보내면, 서버에서 검색해서 클라이언트로 보내주는 프로그램입니다. 이중에서 서버 프로그램중의 일부분입니다.

/* 쉘에서 실행시킬 명령을 완성시킨다 */
command = (char *)malloc(wordLength+10);
snprintf(command, wordLength+10, "./edic \"%s\"", word);
command[wordLength+9] = '\0';
        
/* 프로세스를 하나 더 만들어서, 영어 사전 프로그램을 실행시킨다
 * 그리고 이 프로세스와 통신하기 위한 파이프를 연다 */
fp = popen(command, "r");
free(command);
free(word);

코드에서 보시면 아시겠지만, 쉘에서 직접 영어사전을 실행시키는 방법은
edic "apple" 와 같습니다. 따옴표는 띄워쓰기가 되어 있는 단어를 검색하기 위해 사용하는 것입니다. 예를 들어, edic "jack man" 과 같이 말이죠. 헌데 위와 같이 코드를 짜면, 첫번째 클라이언트는 원하는 제대로된 결과를 받습니다. 그리고 이때 gdb 로 command 를 찍어보아도, "./edic /"apple/"" 와 같이 제대로 출력됩니다. 헌데 두번대 클라이언트 접속 부터는 제대로 그렇지 않습니다. 두번째 클라이언트 접속부터는, gdb 를 이용해서 command 를 찍어보면 "./edic /"apple?" 와 같이 ? 자리에 이상한 문자가 섞여 있음을 알 수 있었습니다. 그리고

sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file

이와 같은 에러도 같이 나더군요..이 에러의 의미가 무엇인지도 궁금합니다.

헌데, 따옴표 기능을 비활성화 시키기위해(즉, 띄워쓰기로 되어 있는 단어 검색은 제대로 안됩니다.) 아래와 같이 코드를 약간 수정한 뒤에는, 첫번째 클라이언트 든지, 두번째 클라이언트 든지에 상관없이, 항상 gdb 로 command 를 찍어보면, "./edic apple" 과 같이 정확히 나옵니다.

/* 쉘에서 실행시킬 명령을 완성시킨다 */
command = (char *)malloc(wordLength+8);
snprintf(command, wordLength+8, "./edic %s", word);
command[wordLength+7] = '\0';
        
/* 프로세스를 하나 더 만들어서, 영어 사전 프로그램을 실행시킨다
 * 그리고 이 프로세스와 통신하기 위한 파이프를 연다 */
fp = popen(command, "r");
free(command);
free(word);

음..이런 경우 어떤 부분을 점검해보면 되는것인가요? 또 이런일이 일어나게 된느 원인이 무엇인지 알고 싶습니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.