Redirect the streams.

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

  1. macrumors newbie

    Joined:
    Jan 26, 2010
    #1
    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?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Looks good to me. Do the same thing.

    -Lee
     
  3. thread starter macrumors newbie

    Joined:
    Jan 26, 2010
    #3
    not helping.

    i would. but it ain't working.

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

    Joined:
    Mar 29, 2009
    Location:
    USA
    #4
    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

    Joined:
    Jan 26, 2010
    #5
    This is what i write:

    Code:
    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

    Joined:
    Sep 2, 2010
    Location:
    Novi Sad, Serbia
    #6
    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 603

    Joined:
    Aug 9, 2009
    #7
    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