LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cannot redirect output to file please help (http://www.linuxquestions.org/questions/linux-newbie-8/cannot-redirect-output-to-file-please-help-4175417947/)

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
<command>

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:

Code:

/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 "10.0.2.15" /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
Code:

echo $result >> result.txt

figure20012 07-21-2012 11:07 PM

result=`ssh "10.0.2.15" /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

figure*;

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?:
Code:

ssh "10.0.2.15" /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
Code:

r=$(ssh 127.0.0.1 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

HTH


All times are GMT -5. The time now is 09:03 PM.