2

I have a shell script.

Say in script test.sh below are thw two prcoess i launch through script

1.echo execute Test.sh start

2.java process1 > /dev/null

3.java process2 > /dev/null

4.echo execute Test.sh finish

5.exit

Now if i run test.sh, say process1 is running and process2 will kill the process1 based on certain condition, so when it kills the process 1, it outputs , this output i want to redirect.

Now output is execute Test.sh start

test.sh line :2 killed pid java process1 > /dev/null

execute Test.sh finish

I want it to look like below, so how to redirect it.

execute Test.sh start

execute Test.sh finish

I hope i am clear in my question framing now

1
  • Do you mean process1 will restart? Commented Jun 11, 2011 at 7:58

1 Answer 1

2

Have you considered redirecting error stream

java process1 > /dev/null 2> /dev/null

java process2 > /dev/null 2> /dev/null

EDIT:
I think you are asking how to redirect bash shell's output. Use the following:

bash > output.txt
java process1 > /dev/null
java process2 > /dev/null
exit

EDIT 2:
Seems like there is only one ugly way to do it, which may not satisfy your needs.

bash > output.txt
java process1 > output1
java process2 > output2
exit
cat output1
cat output2
rm output1 output2

EDIT 3:
It seems there can be another way. Try other shells which may not print out process number when it is killed.

Sign up to request clarification or add additional context in comments.

2 Comments

the echo output has to come, only the killed output should not come, sohow to redirect this?
It was good answer, but this i cannot use because, the echo messages have to be shown on the shell console then and there only !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.