-   Linux - Newbie (
-   -   cannot redirect output to file please help (

figure20012 07-21-2012 07:07 AM

cannot redirect output to file please help
I cannot redirect output to a file.It appears on the bash output
my command is
/usr/java/j2sdk1.4.2_03/bin/java -version > output.txt
the output is display on the bash shell
i want it to be redirected to the file
please help

pixellany 07-21-2012 07:32 AM

Try this:
exec 2 > filename

figure20012 07-21-2012 07:42 AM

thanks a lot pixellany
it worked..:)

silendo 07-21-2012 07:42 AM

you must use this command:


/usr/java/j2sdk1.4.2_03/bin/java -version 2> output.txt

figure20012 07-21-2012 07:43 AM

thnx silendo :)

figure20012 07-21-2012 08:12 AM

i have another problem now
i need to ssh on a remote machine to run the command
result=`ssh "" /usr/java/j2sdk1.4.2_03/bin/java -version`
$result 2>> result.txt

the result is not copied to the result.txt
Can anyone please help me

pixellany 07-21-2012 01:36 PM

redirection only works when some output is being generated. "$result" does not generate any output.

Try using

echo $result >> result.txt

figure20012 07-21-2012 11:07 PM

result=`ssh "" /usr/java/j2sdk1.4.2_03/bin/java -version`
echo $result 2>> result.txt does not work
the result from /usr/java/j2sdk1.4.2_03/bin/java -version is not copied to $result
the echo $result >> result.txt copied null to result.txt
how can i do that Sir?

pixellany 07-22-2012 04:19 AM


You have marked the thread "SOLVED"---this means that most people will not see your new question.

First: What happens if you just do this?:

ssh "" /usr/java/j2sdk1.4.2_03/bin/java -version
Side issue:
It seems that "command 2> filename" does not always work. I'm not sure why

chrism01 07-22-2012 07:09 PM

This works for me as a test

r=$(ssh perl -v)
echo $r  # shows perl version info
echo $r>t.t
cat t.t  # shows perl version info

note that in *nix

0 = stdin
1 = stdout
2 = stderr


All times are GMT -5. The time now is 12:49 AM.