2012-11-04 3 views
0

다른 코드 (pseudo-bash)에서 테스트를 실행해야하는 코드 (1)가 있습니다. 이 코드 (1)는 '사용자 시뮬레이션'에 '기대'를 사용하여 작성합니다.시스템 명령 rm이 예상 프로그램에서 작동하지 않습니다.

문제는이 코드 (1)가 titiExpected.txt를 찾을 수 없을 때 시스템 (이 경우 "rm totoExpect.txt titiExpect.txt"시스템)을 실행할 때 발생하지만 거기에 있습니다!

두 파일간에 차이가 없으며 사용 권한도 동일하기 때문에 그 이유는 생각할 수 없습니다.

# test 5 
proc t5 {} { 
    send "ls > totoExpect.txt\r" 
    send "cat < totoExpect.txt | wc -l > titiExpect.txt\r" 
    send "cat titiExpect.txt\r" 
    expect -re "(0|1|2|3|4|5|6|7|8|9)+.*>" { ok 5; } default { abort 5 } 
    system "rm totoExpect.txt titiExpect.txt" 
} 

그리고 오류 메시지 :

ls > totoExpect.txt 
out: totoExpect.txt 
seq[0]: 'ls' 
-----3 
ensishell>c 
***** TEST 5 ok 

rm: não foi possível remover "titiExpect.txt": Arquivo ou diretório não encontrado 
child process exited abnormally 
    while executing 
"system "rm totoExpect.txt titiExpect.txt"" 
    (procedure "t5" line 6) 
    invoked from within 
"t5" 
    ("eval" body line 1) 
    invoked from within 
"eval "t$t;" " 
    ("foreach" body line 1) 
    invoked from within 
"foreach t {0 1 2 3 4 5 6 7} { eval "t$t;" } " 
    invoked from within 
"expect_user { 
    -timeout 30 "auto\n" { 
    puts "AUTO:\n"; 
    foreach t {0 1 2 3 4 5 6 7} { eval "t$t;" } 
    } 
    -timeout 30 -re "(\[\]+)\..." 
    (file "./testshell.expect" line 99) 
make: ** [test] Erro 1 

경우 "RM : NAO FOI possível 제거"titiExpect.txt 여기

코드 (1) 문제가 제기 곳의 일부입니다 ":은"rm : "titiExpect.txt"파일이나 디렉토리를 찾을 수 없습니다 (죄송합니다 ...).

및 this 인 LS 그냥 오류 메시지가 후 (그래서 titiExpect.txt이 야해) -l :

-rwxrwxr-x 1 fernando  fernando 273 Out 23 17:53 #Makefile# 
-rwxrwxr-x 1 fernando  fernando 6238 Nov 5 21:18 #ensishell.c# 
-rwxrwxr-x 1 fernando  fernando 1271 Out 24 20:30 #readcmd.h# 
-rwxrwxr-x 1 fernando  fernando 3250 Nov 5 21:07 #testshell.expect# 
-rwxrwxrwx 1 fernando  fernando 303 Out 24 20:21 Makefile 
drwxrwxr-x 2 fernando  fernando 4096 Nov 4 19:06 SEPC shell 
-rw-rw-r-- 1 fernando  fernando 193453 Out 18 18:25 Sujet_shell.pdf 
-rwxrwxr-x 1 fernando  fernando 25451 Nov 5 21:17 ensishell 
-rwxrwxrwx 1 fernando  fernando 6238 Nov 5 20:32 ensishell.c 
-rw-rw-r-- 1 fernando  fernando 10664 Nov 5 21:17 ensishell.o 
-rwxrwxr-x 1 fernando  fernando 7251 Nov 4 00:33 foo 
-rw-rw-r-- 1 fernando  fernando 173 Nov 4 00:33 foo.c 
-rw-rw-r-- 1 fernando  fernando  16 Nov 4 01:15 in.txt~ 
-rwxrwxrwx 1 fernando  fernando 6603 Out 23 00:37 readcmd.c 
-rwxrwxrwx 1 fernando  fernando 1271 Out 23 01:24 readcmd.h 
-rwxrwxrwx 1 fernando  fernando 1271 Out 23 00:37 readcmd.h~ 
-rw-rw-r-- 1 fernando  fernando 11216 Nov 5 21:17 readcmd.o 
-rwxrwxrwx 1 fernando  fernando 3250 Nov 5 20:41 testshell.expect 
-rwx------ 1 fernando  fernando 1263 Nov 5 12:43 toto.txt 

최악의 문제는이 코드 수정이 안된다, 그러나 그 날이 보인다하면 프로그램 오류입니다 이것은 실패합니다. (사실, 문제를 해결하는 라인을 주석 ..)

어떤 아이디어?

+0

파일 권한'totoExpect.txt' 및'titiExpect.txt' 파일들? – askmish

+0

두 사용자 모두 rwx – FernandoP

답변

3

보세요.

# test 5 
proc t5 {} { 
    send "ls > totoExpect.txt\r" 
    send "cat < totoExpect.txt | wc -l > titiExpect.txt\r" 
    send "cat titiExpect.txt\r" 
    expect -re "(0|1|2|3|4|5|6|7|8|9)+.*>" { ok 5; } default { abort 5 } 
    system "rm totoExpect.txt titiExpect.txt" 
} 

첫 번째 sendtotoExpect.txt\r라는 이름의 파일을 상자.

두 번째 sendtitiExpect.txt\r이라는 파일을 생성합니다. totoExpect.txt 파일이 없기 때문에 cat 부분은 실제로 실패합니다. 그러나 명령이 파이프의 마지막 명령이 아니고 파이프의 일부이기 때문에 expect가 오류로 간주하지 않습니다. (당신이 볼 수있는 것은 titiExpect.txt\r 파일이 비어 있다는 것입니다.)

위의 \r은 CR 문자이며, 아마도 당신이 그것을 놓친 이유입니다. 리눅스에서는 파일 이름에 완벽하게 허용되는 문자입니다 (/\0 만 사용 가능). 테스트에서 제거하면 제대로 작동합니다. 당신이 그것을 유지를 주장하는 경우

또는, 다음 일관되게 유지 : 파일을 제거 할 때

마지막으로
# test 5 
proc t5 {} { 
    send "ls > totoExpect.txt\r" 
    send "cat < totoExpect.txt\r | wc -l > titiExpect.txt\r" 
    send "cat titiExpect.txt\r" 
    expect -re "(0|1|2|3|4|5|6|7|8|9)+.*>" { ok 5; } default { abort 5 } 
    system "rm totoExpect.txt\r titiExpect.txt\r" 
} 

, 그것이 -f 플래그를 사용하는 것이 좋습니다, 그래서 rm는 파일 중 하나 불평하지 않습니다 존재하지 않는다.

나의 제안은 그 이상한 \r의 근절

# test 5 
proc t5 {} { 
    send "ls > totoExpect.txt" 
    send "cat < totoExpect.txt | wc -l > titiExpect.txt" 
    send "cat titiExpect.txt" 
    expect -re "(0|1|2|3|4|5|6|7|8|9)+.*>" { ok 5; } default { abort 5 } 
    system "rm -f totoExpect.txt titiExpect.txt" 
} 

로 그 테스트를 다시 작성하는 것입니다.

+0

나는 마지막 줄에 대해서만 +1 할 것입니다. –

+0

답변으로 감사합니다. 사실 (그게 내 잘못이었습니다. 나는 그것을 말하지 않았습니다.) 명령 판독기는 \를 이스케이프 문자로 사용했습니다. , 그래서 저장된 이름은 \ r에 의해 끝나지 않습니다. 그래서 전혀 작동하지 않는 것을 제거하십시오 .. 저는 여전히 문제가 있습니다 만, -f가 실제로 도움을주었습니다. 적어도 이제는 크래시가 발생하지 않았습니다 ... – FernandoP

+0

@FernandoP : 실제로 확인 했습니까? 리눅스에서는'\ r' = CR = ASCII 13은 파일 이름에 유효한 문자입니다. 실제 Bash 쉘에서'touch $ 'titiExpect.txt \ r''를 실행하면 무슨 뜻인지 알 수 있습니다. ('$ 'foo'는 Bash에서 C 스타일 백 슬래시 이스케이프로'foo'를 지정하는 방법입니다.) –

관련 문제