Java with Unix (Redirection + Piping)


 
Thread Tools Search this Thread
Top Forums Programming Java with Unix (Redirection + Piping)
# 1  
Old 04-29-2008
Bug Java with Unix (Redirection + Piping)

Hi,

To explain this question I will have to go into a bit of detail. I hope you don't mind.

currently I have a log handler (an already compiled c++ version) and what it does is makes a log file and writes all the unix output (echo, etc) of a script to that log file. To me the log_handler is a black box.
The log_handler is called through another script called "run_application"
(e.g. run_application somescript1 2>&1 > /dev/null )

RUN_APPLICATION script is just this:

APPLICATION=$@
LOGNAME=`basename $APPLICATION`

if [ -n "$APPLICATION" ]
then
$APPLICATION 2>&1 | /bin/log_handler $LOGNAME &
fi


Now my question is. Is it log_handler thats taking the script and logging it or is it being done through redirection and piping?? And if so how does it work? What does the 2>&1 do?

The second part would be to mimic this in java but i guess thats another thread. Smilie

Thanks all for the help.
# 2  
Old 04-29-2008
Simply ask google about "2>&1" and you're done.

PS: you aren't doing homework, are you?
# 3  
Old 04-30-2008
Umm... sorry i graduated so I dont get any homework. I did type it into "unix 2>&1" but google eats the > and &. And also the google answer won't be specific to my question.

You just assumed that I am a student. Infact I am recently hired Business Analyst working in the IT department. The guy who is supposed to start coding the log handler in java will start in a couple of weeks. So I thought since I have time on my hands, I will help him out and try to understand how this thing works in c++ and maybe offer some real input.

And fabtagon, I sincerely hope that if you had a question regarding Free Cash Flow, you wouldnt get the same response you gave me.

p.s. As far as doing my work is concerned (which is more to do with investigation than coding hence the business degree), I did find out one thing. Fabtagon you have a special psychic ability to find out which questions is a homework question and which is a proper real life question. Now can you tell me where to find that shirt I lost?

Last edited by fluke_perf; 04-30-2008 at 10:37 AM..
# 4  
Old 04-30-2008
fluke_perf: these forums have a serious homework problem, don't take it personally.

2>&1 is a redirection, yes; it directs standard error to the same place as standard output.

Without knowing what log_handler is doing, strictly speaking, it's not really possible to answer your question. The script runs APPLICATION and feeds its output and error streams to log_handler, so I suppose we can infer that if any actual logging to files is taking place, that one is taking care of that part.

For what it's worth, "$@" should always have double quotes around it.

The shirt is in the second drawer from the right; if you're lucky, you'll find an Intro to Unix Shell Scripting book there, too.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Unix Piping Problem

Hey guys. I'm very new to Unix. I'm pretty fluent in Java and C, but I have never actually used Unix for anything. I am in an Operating Systems course now and I have an assignment to write a piece of code that involves forks and piping. I'm stuck. 1. The problem statement, all variables and... (6 Replies)
Discussion started by: itsjimmy91
6 Replies

2. Shell Programming and Scripting

Exit code from piping in unix shell script

Hi , I have following code in my shell script : "$TS_BIN/tranfrmr" "${TS_SETTINGS}/tranfrmr_p1.stx" "${TS_LOGS}/tranfrmr_p1.err" | ( "$TS_BIN/cusparse" "${TS_SETTINGS}/cusparse_p2.stx" "${TS_LOGS}/cusparse_p2.err" | ( "$TS_BIN/tsqsort" "${TS_SETTINGS}/srtforpm_p3.stx"... (8 Replies)
Discussion started by: sonu_pal
8 Replies

3. UNIX for Dummies Questions & Answers

redirection in unix

how to redirect a output value to a file (1 Reply)
Discussion started by: pratima.kumari
1 Replies

4. Shell Programming and Scripting

Piping Unix Variable Array values into AWK

#ksh Here is my code: ERRORLIST="43032 12001 12002 12003 12004 34019 49015 49016 49017 49018 49024 49025 49026 58004 72003 12005 12006 12007 12008 12011 12012 16024 16023" for ERROR in ${ERRORLIST} do awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print... (3 Replies)
Discussion started by: k1ko
3 Replies

5. Programming

piping from C to python in UNIX

Hi, I'm trying to wrap my head around piping in C - I've got a small C program that forks and pipes stuff from the child process to the parent process. Currently the child process calls a C program that squirts out random numbers which then pipes the result to the parent process. The... (0 Replies)
Discussion started by: Dreams in Blue
0 Replies

6. Filesystems, Disks and Memory

Unix command redirection

Hi all,, Is there any way to redirect the command o/p directaly to a memory location instead of redirecting it to the file?? (1 Reply)
Discussion started by: swap007
1 Replies

7. UNIX for Dummies Questions & Answers

Unix redirection to '&-'

Hi UF family members, I am intermediate in Unix language and scripting.I know the redirection systems in unix,but the below statement confuses me: #!/bin/ksh . $HOME/.profile 2>&- Actually this is an extract from a unix script which was trying to set the... (6 Replies)
Discussion started by: DILEEP410
6 Replies

8. UNIX for Dummies Questions & Answers

Piping in UNIX

All, I am a UNIX novice with a question that I hope you can help me with. I have a UNIX application called "Tole" that formats and displays specific information about customers. I can display the information for up to 30 customers by seperating customer IDs using commas in this format: Tole -c... (3 Replies)
Discussion started by: simo007
3 Replies

9. Programming

Piping and redirection implementation

To implement the facility of piping and redirection I used the two commands dup, dup2, and strtok for tokenizing the command. But when I run the command ls|more it is not running fine as I have developed it using the dup2 command. the more command needs the whole buffer at once. Please help... (7 Replies)
Discussion started by: mobile01
7 Replies

10. Shell Programming and Scripting

Redirection or piping error message

I have written a script that appears to work correctly in testing, but is coming up with a starnge error message, script_name: test: 0403-004 Specify a parameter with this command. Redirection or piping of stdin or stdout is allowed only with -b. (156). The script is run by different... (2 Replies)
Discussion started by: mariner
2 Replies
Login or Register to Ask a Question