1

I'm having issues getting redirection to work in Terminal. I'm in a C++ class where we have to create an application, then find that application in the Terminal and place a text file in the same folder. That text file then has to be used as the input to the Terminal application we created in C++. So, after building my application and placing it and a .txt file in a folder, I open the Terminal, navigate to that directory, then use:

program < textfile

or more specifically in my case:

redirect < input.txt

but it doesn't work. I keep getting: "-bash: redirect: command not found"

I'm using the method our teacher told us to use based on windows command line, but I'm betting its not the same format for Terminal on Mac. I've been googling the issue for about a week and still have not figured it out. Any help would be greatly appreciated.

EDIT:

Added a photo:

enter image description here

EDIT2:

enter image description here

  • 1
    If you are running a program you compiled and it's not in /bin/, you have to use ./programName. Try ./redirect < input.txt. But I can't say for sure. – Arc676 Jan 26 '16 at 3:24
1

Far less can go wrong if you pipe the input:

cat words.5.txt | /path/to/redirect

In your case, ./program might be needed depending on where you are compiling things or omitting the path entirely. From your edit this should work too:

./redirect < words.5.txt

That bash error is due to the program not existing in $PATH

echo $PATH
  • 1
    Thank you very much, I'll give this a shot soon, I edited my post and added a photo of the terminal, not sure if that will help at all. I compiled the C++ program with Xcode and then just saved a copy of the built program to my desktop in a generic folder so I didn't have to do a ton of directory navigating to get to that default location of the program that Xcode builds. – joe_04_04 Jan 26 '16 at 3:31
  • This solved half of my problem, got the input to work using the ./redirect < words.5.txt, but the program isn't running now. My "redirect" application is just a test application I wrote to make sure that I could get redirection to work before I actually did the homework, which is much more laborious coding. So the redirect program just mirrors the input so I know its working, but with the redirection, its giving the program the input now, but no output. I added another photo in my original post that shows the program working when running it, but not outputting with redirection. – joe_04_04 Jan 26 '16 at 5:41
  • @joe_04_04 Best to wrap up the initial problem - accept an answer and then perhaps ask a follow on question. Also - take moment to look at help center since we don't do code level questions and you might look to stack overflow or another site if your program isn't running itself. The basics of bash scripting are on topic here which is what you needed to know to get things connected - data file to program file and to execute the program. best of luck with your journey and this problem set specifically. – bmike Jan 26 '16 at 14:12
  • Hey Mike, I'll accept the answer, but I do know that my code isn't the issue. The program itself is the part I know the best, just not the Terminal command. I'll ask the question again and see why output isn't working now after redirection. – joe_04_04 Jan 27 '16 at 3:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .