Redirect the streams.

Discussion in 'Mac Programming' started by Extreme343GS, Sep 15, 2010.

  1. macrumors newbie

    Jan 26, 2010
    We usually do this for windows:

    java test < in.txt > out.txt
    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?
  2. macrumors 68040


    Jan 10, 2005
    Dallas, TX
  3. thread starter macrumors newbie

    Jan 26, 2010
    not helping.

    i would. but it ain't working.

    -bash: in.rtf: No such file or directory
    but "in.rtf" is in the working directory.
  4. macrumors 68000

    Mar 29, 2009
    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
  5. thread starter macrumors newbie

    Jan 26, 2010
    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.
  6. macrumors newbie

    Sep 2, 2010
    Novi Sad, Serbia
    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
  7. macrumors 604

    Aug 9, 2009
    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.

Share This Page