IM 6.5.9-8 Q16 Mac OSX Tiger
I have written a script for a client (running Linux). It works standalone, but the client wants to launch it from another tool, webc. It does not work and I am trying to figure out why.
How would I go about sending error messages from the terminal to a text file.
Here is the command it does not like:
convert someimage -quiet -regard-warnings tmp.mpc
I have tried
convert someimage -quiet -regard-warnings tmp.mpc || 2>> errorfile.txt
But that does not seem to catch the errors. They still go to the terminal. Same for 2>&1 and 1>&2
Thanks
P.S.
Any suggestions about configuring IM so that his scripting tool will talk well with IM. It appears that when my bash script is launched from his webc, it fails to run IM convert (properly). I am not enough of a Unix person to know what is wrong. We are trying to look at system error logs to see what that might tell us. But currently it seems to report something like:
convert: unable to open image `./scriptname_1_2670.mpc': \xd0\xa1\x04\b \xc20@h%\xff\xbf
Fred
redirect errors to textfile
Re: redirect errors to textfile
Having a search on google I have found:
The standard way of redirecting the output of a command into a file is to use the 'tee' command:
# Starts 'my_command' command and duplicates
# the outputs from the standard and error devices
# into the 'my_log.txt' log file
my_command 2>&1 | tee my_log.txt
About tee
Read from an input and write to a standard output or file.
Syntax
tee [OPTION]... [FILE]...
-a
--append Append to the given FILEs, do not overwrite.
-i ignore interrupt signals.
--help Display the help screen.
--version Display the version.
Examples
ls *.txt | wc -l | tee /dev/tty count.txt
In the above example the ls command would list all .txt files in the current directory, take a word count (wc) by the amount of lines (-l) and the output displayed to the /dev/tty (terminal) will be sent to the count.txt.
Note: Because the above example did not take advantage of the -a or append option if the count.txt file already existed it would have been overwritten.
Related commands
cat
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: redirect errors to textfile
Thanks Anthony, that works. Learned something new about unix today.
Fred
Fred