Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Following my previous post, I still have one annoying bug that won't leave .

I wrote a simulator for the bash command under Linux.

When I run my code in a single run, with the these commands:

ls Debug/ | grep r
ls >> file.jer & ls & ls & ls &
ls >> file.jer
ls > file1.rrr
ls & ls | grep e
ls & ls & ls &
ls Debug/ | grep r
ls Debug/ > k.out
ls Debug/ >> k.out

then in the third line ls >> file.jer the program writes ls: cannot access : No such file or directory . When I run the program and every run I hit the inputs separately then the correct output is presented. I've tried to debug this so many times, but couldn't find the problem.

Specific problem: when I run the code and hit ls Debug/ | grep r , the correct output is presented. Following that, when I hit ls >> file.jer & ls & ls & ls & , also here the code works great. But when I hit ls >> file.jer , then something very wrong is happening, and I can't seem to find its source , where again the output for the 3rd command is No such file or directory , but clearly it's wrong, since when I run it in a single run, the file file.jer is appended with the contents of the current path.

I have a main, and two .h files with their two .c files.

share|improve this question

closed as off topic by Mat, Gilles, Michael Mrozek May 29 '12 at 5:13

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This is way, way too much code. Use a debugger, or printfs right around your call to exec or whatever you're using to start ls, and check the contents of the argument array. –  Mat May 28 '12 at 9:23
@Mat: I know , I've tried to debug this , a lot , but couldn't find the source of this problem . I suspect that the source is exec but printf-s didn't produce any result. Do you something wrong somewhere ? any yes ,I know this is very complex request ... –  ron May 28 '12 at 9:26
No, there's just way too much code. I can't even find any exec site. Use a debugger, break on exec and inspect argv, there's probably a zero-length string (or unprintable garbage) in there. –  Mat May 28 '12 at 9:31
Aren't you getting in a recursive loop in lines 2 (with the & putting the command in the background) and line three appending more data to the open file? –  jippie May 28 '12 at 11:36
@Mat: You were right. thanks , it solved the problem ! –  ron May 28 '12 at 18:30

1 Answer 1

Problem solved!

The reason for the bug was that I sent a char** variable into a function that changes that variable , and then , I free that variable back in main . This is not allowed , hence I needed to send a char*** and then everything worked out .

Thanks everybody.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.