PDA

View Full Version : Redirect the streams.




Extreme343GS
Sep 15, 2010, 04:26 PM
We usually do this for windows:

java test < in.txt > out.txt
or
test.exe < in.txt > out.txt

to direct i/o stream i/p and o/p to the in.txt and out.txt respectively.

How do i do it in osx?



lee1210
Sep 15, 2010, 04:33 PM
Looks good to me. Do the same thing.

-Lee

Extreme343GS
Sep 15, 2010, 06:40 PM
i would. but it ain't working.

-bash: in.rtf: No such file or directory

but "in.rtf" is in the working directory.

robvas
Sep 15, 2010, 07:04 PM
What is the whole command you are using?


To make the contents of a file serve as the input to a command, use "<":

$ wc < RightNow.txt
2 12 58

As is so often the case in shell programming, there is at least one other way to produce the above result:

$ cat RightNow.txt | wc
2 12 58

Extreme343GS
Sep 16, 2010, 01:37 AM
This is what i write:

Program\ Files/Scripter/test <in.rtf> out.rtf


in terminal. What i expect to happen is that the "cin>>" or any other I/P stream command takes the I/P from the in.rtf. Works as a good test case model for I/P values.

Btw i just the problem. you need to change the working directly with "cd".
Thanks anyways.

toptan
Sep 16, 2010, 12:58 PM
On Unix environments current directory is not in the search path, so if your files in.rtf and out.rtf are in the current directory proper way to address them is:
./in.rtf and ./out.rtf.

Your command should look like java < ./in.rtf > ./out.rtf

chown33
Sep 16, 2010, 01:13 PM
On Unix environments current directory is not in the search path, so if your files in.rtf and out.rtf are in the current directory proper way to address them is:
./in.rtf and ./out.rtf.

Your command should look like java < ./in.rtf > ./out.rtf

Files used as command arguments or redirections don't have to be in the search path.

There is no functional difference between "./in.rtf" and "in.rtf" when used as stream redirections. There would be a difference if they were used as a command, but they're not being used that way, so it's irrelevant.