Thread: IO Redirect error.

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    19

    IO Redirect error.

    I created a program to count the number of characters in a file, it compiles fine and is a really basic program. When I go to redirect a text file to the program I get an error. chrcnt is the compiled program and words is the text file. I use:

    chrcnt < words

    and I get the error

    chrcnt: program not found

    I am using ubuntu, any ideas as to why its not working?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Try
    ./chrcnt < words
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    19

    Yep

    Quote Originally Posted by Salem View Post
    Try
    ./chrcnt < words
    Yep, that did it. Thank you very much.

  4. #4
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by dtow1 View Post
    why its not working?
    Because by default, current working directory is not one of the directories where executables are searched for.

    Explicitly writing the relative path to the executable (./chrcnt)is just the way you tell the OS to not do any kind of search for it, but just run chrcnt in the current directory. No ambiguity, no search, only results you want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DNS Filter ( Redirect)
    By jhsedona in forum C Programming
    Replies: 1
    Last Post: 04-08-2012, 04:20 PM
  2. redirect output
    By Maga in forum C Programming
    Replies: 5
    Last Post: 02-27-2010, 04:58 AM
  3. Redirect stdout using dup
    By spank in forum Linux Programming
    Replies: 13
    Last Post: 04-03-2008, 05:16 PM
  4. Redirect FAQ...
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 05-21-2007, 04:48 PM
  5. DLL Redirect
    By username in forum Windows Programming
    Replies: 5
    Last Post: 05-30-2003, 09:58 AM