I am trying to put into a file an error that the system gives me.
I have the following script:
#!/bin/bash
logfile="output.log"
echo "Starting" > $logfile
./cpi 2>&1 >> $logfile
echo "Ending" >> $logfile
exit
And the output I get in the file output.log is the following:
Starting
Ending
But in the screen I see this:
./cpi: error while loading shared libraries: libmpich.so.3: cannot open shared object file: No such file or directory
The error is on purpose. I took the path to that lib out of my #LD_LIBRARY_PATH. The point is, if the script runs in another machine and the library isn’t there, I would like to get the error that goes to the screen.
I also need the output of my own program, thus I need the 2>&1 >> $logfile after its execution.
Any thoughts?
I may be misunderstanding.
If you want both the standard output and standard error from
cpito go to$logfile, swap the order of the redirections: