8
#!/bin/bash
./program < input.txt > output.txt

The > output.txt part is being ignored so output.txt ends up being empty.

This works for the sort command so I expected to also work for other programs.

Any reason this doesn't work? How should I achieve this?

2
  • 2
    Perhaps the output from ./program is going to the standard error? Try 2> output.txt Commented Apr 9, 2012 at 16:59
  • @Richante LOL that's odd but now works (why do you write the answer in a comment?) thanks Commented Apr 9, 2012 at 17:08

1 Answer 1

15

The most likely explanation is that the output you're seeing is from stderr, not stdout. To redirect both of them to a file, do this:

./program < input.txt > output.txt 2>&1

or

./program < input.txt &> output.txt
Sign up to request clarification or add additional context in comments.

1 Comment

How would you do something like ./program < input.txt | program2 | program n > output.txt ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.