2013-02-26 23 views
0

這裏是我當前的makefile,它不能正常運行測試:作爲換行符如何使用makefile來測試我的shell實現?

shell2: shell2.o 
shell2.o: shell2.c 

clean:  
     rm -f *.o 

test: shell2 
     ./shell2 
     pwd 
     ./shell2 
     cd .. 
     ./shell2 
     jobs 
     ./shell2 
     sleep 100 & 
     jobs 
     ./shell2 
     exit 

我的程序測試時,已經進入了一個命令就知道了。這是我 程序的輸出,當我手動編譯自己:

$ pwd 
/students/8/[redacted]/[redacted]/Shell2 
$ cd .. 
$ jobs 
Jobs: 
$ sleep 1000 & 
To the background: 20203 
$ jobs 
Jobs: 
20203 
$ jobs 
Jobs: 
20203 
$ killall sleep 
sleep(17014): Operation not permitted 
sleep(17305): Operation not permitted 
sleep(17433): Operation not permitted 
sleep(19741): Operation not permitted 
sleep(19841): Operation not permitted 
sleep(20041): Operation not permitted 
sleep(20183): Operation not permitted 
$ jobs 
Jobs: 
$ exit 
now exiting... 

這裏是輸出,當我運行make測試:

make test 
./shell2 
$ pwd 
/students/8/[redacted]/[redacted]/Shell2 
./shell2 
$ cd .. 
./shell2 
$ jobs 
make: jobs: Command not found 
make: *** [test] Error 127 

而且,我必須按ctrl + d,每次在測試期間執行新的一行。

我想寫這個Makefile我的課,這樣我可以提交我的任務,我的教授沒有解釋在所有如何使用一個makefile除了基本的 ./a.out [輸入指令]

他從來沒有解釋如何在程序運行在像shell一樣的連續循環的情況下如何使用makefile,等待用戶按下[enter]或新行來解析命令。

我檢查了GNU man的make,但在「測試」部分沒有解釋太多。

感謝您的幫助,我非常感謝。

test_input.txt的輸出:

./shell2 < test_input.txt 
"Sending command: pwd" 
/students/8/[redacted]/[redacted]/Shell2 
"Sending command: cd .." 
"Sending command: pwd" 
/students/8/[redacted]/[redacted] 
"Sending command: jobs" 
$ $ $ $ $ $ $ $ Jobs: 
$ 
"Sending command: sleep 1000 &" 
$ $ To the background: 27199 
"jobs" 
$ $ Jobs: 
27199 
$ 
"Sending command: killall sleep" 
$ $ $ $ Jobs: 
"Sending command: jobs" 
$ $ now exiting... 
"exit" 

test_input.txt:

echo "Sending command: pwd" 
pwd 
echo "Sending command: cd .." 
cd .. 
echo "Sending command: pwd" 
pwd 
echo "Sending command: jobs" 
jobs 

echo "Sending command: sleep 1000 &" 
sleep 1000 & 
echo "jobs" 
jobs 

echo "Sending command: killall sleep" 
killall sleep 
echo "Sending command: jobs" 
jobs 
echo "exit" 
exit 
+0

發佈您的代碼,以便我們可以測試它 - – 2013-02-26 04:02:58

回答

1

它看起來像你想提供輸入到你的程序。你不能用make(直接)做這個,只需用/bin/sh -c COMMAND執行每一行即可。

你可以做的是

test: shell2 
    ./shell2 < test_input.txt 

輸入重定向到文件test_input.txt,其中將包括你想要的命令。

+0

好吧,我現在越來越近了,非常感謝。我的test_input.txt文件已經上傳:出於某種原因,我沒有得到相同的輸出,如果我只是手動進行。現在,test_input.txt的輸出現在與test_input.txt本身一起發佈。 – Harrison 2013-02-26 17:18:17

+0

經過進一步檢查,我發現命令進入shell並正確執行,但輸出仍然有點「瘋狂」字符,它只應該在每一行中出現一次。我手動測試程序)。測試輸入也沒有顯示它提供給外殼的輸入,所以我手動回顯了每個命令,因爲不知道更好的解決方案。 – Harrison 2013-02-26 17:28:46

+0

@HarrisonNguyen看來你的原始問題已經回答了;接受答案,然後問你一個新問題(儘管看起來你可以自己處理)。 – anatolyg 2013-02-26 20:27:11

相關問題