Reputation: 430
Here is my current makefile, which does not run test correctly:
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
My program tests for newline to know when a command has been entered. This is the output of my program when I compile it myself manually:
$ 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...
Here is the output when I run make test:
make test
./shell2
$ pwd
/students/8/[redacted]/[redacted]/Shell2
./shell2
$ cd ..
./shell2
$ jobs
make: jobs: Command not found
make: *** [test] Error 127
Also, I have to hit ctrl+D every time for a new line to execute during make test.
I'm trying to write this makefile for my class so that I can submit my assignment, my professor did not explain at all how to use a makefile besides the basic ./a.out [input command]
He never explained how to use a makefile in the case that your program is running on a continuous loop like a shell is, waiting for the user to press [enter] or new line for the command to be parsed.
I checked the GNU man for make but it didn't explain much in the "testing" section.
Thanks for your help, I really appreciate it.
test_input.txt's output:
./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
Upvotes: 0
Views: 407
Reputation: 85837
It looks like you're trying to supply input to your program. You can't do this with make (directly) as make simply executes each line with /bin/sh -c COMMAND
.
What you can do is
test: shell2
./shell2 < test_input.txt
to redirect input to the file test_input.txt
, which would contain the commands you want.
Upvotes: 1