about the FileNotFoundException in cat command

when we use:
cat xxx > xxx
It seems that this command never go into the CatCommand class.
I'm now tracking this into the CommandLine class and CommandShell class.

What are you really trying to do?

The command 'cat xxx > xxx' says read 'xxx' and write it to 'xxx'. It doesn't make sense to me.

Perhaps you are actually trying 'cat xxx > yyy'? That will work if 'xxx' exists in the current directory. If not, a FNFE is expected. Note that your current directory starts out as '/' not '/jnode/home' as you might expect.

BTW: I'm in the middle of a large-scale rework of the shell's handling of '<', '>' and '|'. So there is a good chance that the results of your investigation will be nugatory. [There's a word that you don't often see used :-)]

I type

I type
cat "123" > a.txt
in /jnode/tmp
It says FNFE.But I don't think it has gone into CatCommand class.I added some 'System.out' in the class, I didn't see the result.

nugatory is realy a new word for me:-)
It doesn't matter my work is nugatory, I just get familiar with the projuect:)

Cat is not echo

I think you are misunderstanding the purpose of the "cat" program.

When you run 'cat "123" > a.txt', you are telling 'cat' to open and read a file named '123' in the current directory, and write its contents to 'a.txt'. If there is no file named '123', the FNFE is expected. (OK ... so we shouldn't really print a stack trace, but that is just there temporarily for debugging purposes.)

If you want to write the string '123' to 'a.txt', you should be running 'echo "123" > a.txt'.

The double quotes are actually unnecessary in both cases above. What that are doing is telling the shell to pass the characters '123' to the command as one argument, which it would do anyway. Here is an example where the double quotes are necessary: 'cat "file name" > a.txt'. Here, the name of the file we are trying to catenate has a space character in its name. We could also write the above as 'cat file\ name > a.txt'.

By the way, JNode's 'cat' and 'echo' commands, and the shell's quoting and file redirection are all modeled on classical UNIX. If you are not familiar with UNIX (or Linux), I suggest that you get hold of a good book or web tutorial.

thank you:-)

thank you:-)