Page 1 of 1

redirect errors to textfile

Posted: 2010-02-20T13:09:48-07:00
by fmw42
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

Re: redirect errors to textfile

Posted: 2010-02-20T13:52:00-07:00
by Bonzo
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

Re: redirect errors to textfile

Posted: 2010-02-20T14:06:22-07:00
by fmw42
Thanks Anthony, that works. Learned something new about unix today.

Fred