Start subshell with different STDOUT


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Start subshell with different STDOUT
# 1  
Old 03-23-2006
Start subshell with different STDOUT

Hello
Before I get to my question let me explain the situation. I am writing a ksh script to startup several instances of an application. That is done by executing another ksh script (let's call it startApp) with some arguments. Now, startApp writes some information to stdout that I don't want displayed from my master script. However, it also redirects stdout to a log file and writes important information that is needed. When I try
Code:
startApp arg1 arg2 > SOME_FILE

in the master script, the log file is not created. I understand that when I execute startApp from within my script, startApp's subshell inherits stdin and stdout. Is there a way to execute startApp in a completely new shell that does not share stdout with the calling shell?
Thanks,

EvilBoz
# 2  
Old 03-23-2006
I don't know about a new stdout, and this may be over simplified, but it may be the single > that may be overwriting the previous log entries. You could try
Code:
startApp arg1 arg2 >> SOME_FILE

This could easily be debugged by using
Code:
startApp arg1 arg2 | tee SOME_FILE

If your log ends up empty use
Code:
startApp arg1 arg2 | tee -a SOME_FILE

These will redirect the output to both stdout and the file. The difference is the "-a" appends the output. Same as the ">>" but echos to the screen as well.

Judging by your example. Unless StartApp has something that forks to a background process you should not run into trouble with stdout.

MPH
# 3  
Old 03-23-2006
I tried using
Code:
startApp arg1 arg2 | tee SOME_FILE

but that had quite the opposite effect of what I need. It did create the log file but it also printed everything that was supposed to go to the log file to the screen. BTW, the only reason I was using
Code:
startApp arg1 arg2 > SOME_FILE

was to avoid anything being printed to the screen. SOME_FILE is either some temp file or /dev/null. The log file I need is created by startApp and not by the master startup script.
The problem is that either startApp or some other script it calls redirects stdout to the logfile. However, when I redirect output when I call startApp, the following redirects don't seem to have the desired effect.
# 4  
Old 03-23-2006
I think I miss-read your initial post. I was under the impression that the log file was created by the redirect in the code example you gave initially.

With the assumtion that StartApp itself generates the log file. Which more than likely would be a printf to the file instead of a stdout redirect. Is it possible that the StartApp is directing the screen output to stderr instead of stdout? When you use:
Code:
startApp arg1 arg2 > SOME_FILE

does it still output to the screen? If this is the case in the master script you could try:
Code:
startApp arg1 arg2 > SOME_FILE 2>&1

If not I may need more info on what type of program it is to get a better idea of the problem. Just a thought.

MPH
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Have each subshell write stderr and stdout to its own logfile

Hello, As stated in the title, I do some hacked parallel processing by running multiple instances of bash scripts, each in their own subshell. The code looks like this, # launch one batch-train script in background for each value in fold group list for FOLD_GROUP in "${FOLD_GROUP_LIST}" do ... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

Help sending mail through subshell

Hey I have a shell script that is like this: ( echo "hi!" ##DO SOMETHING )&( sleep 5 ##EMAIL RECIPIENTS VARs ERECIPIENT3="email.com" echo "Connection on status: is Down"|mail -s "Subject:" ${ERECIPIENT3} kill -- -$$ ) This isn't working anyone know why? mail won't go out from... (12 Replies)
Discussion started by: mo_VERTICASQL
12 Replies

3. Shell Programming and Scripting

Getopts in the subshell of ksh

Hi, the getopts doesnt seem to be working in the subshell of the ksh. when I echo $@ and $* from the subshell it shows nothing. even when I am capturing the parameters from the outer shell and passing while invoking the file then I am still not getting it properly. the below code is in the... (9 Replies)
Discussion started by: hitmansilentass
9 Replies

4. Shell Programming and Scripting

While loop subshell problem

People, Here is my code while read ln do xyz=$(echo $ln/$val1*100-100|bc -l|xargs printf "%1.0f\n") if && ; then iam="YELLOW" fi done <<< "$(grep "^" $TMPOUT)" where $TMPOUT is a flat file which contains a set of values. Whilst executing the above, I get an error... (4 Replies)
Discussion started by: sathyaonnuix
4 Replies

5. Shell Programming and Scripting

Basename in subshell

Hi All, I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name. This one works fine for files in main directory, but not for... (4 Replies)
Discussion started by: new_item
4 Replies

6. Shell Programming and Scripting

redirect stdout and stderr to file wrong order problem with subshell

Hello I read a lot of post related to this topic, but nothing helped me. :mad: I'm running a ksh script with subshell what processing some ldap command. I need to check output for possible errors. #!/bin/ksh ... readinput < $QCHAT_INPUT |& while read -p line do echo $line ... (3 Replies)
Discussion started by: Osim
3 Replies

7. Shell Programming and Scripting

getopts in a subshell

Hello, I've a little problem with one of my ksh scripts and I manage to narrow it to the script here: #!/bin/ksh writeLog() { paramHandle="unknown" OPTIND=1 while getopts :i: option $* do case $option in i) paramHandle=${OPTARG} ;; esac done echo... (2 Replies)
Discussion started by: Dahu
2 Replies

8. Shell Programming and Scripting

Killing a subshell

I am calling a script from with another script and reading its output one line at a time (using <childscript> | while read line) in the parent script. If the output exceeds a predefined number of lines I want to kill the child shell from within the parent shell. I decided to print the process ID... (2 Replies)
Discussion started by: slash_blog
2 Replies

9. Shell Programming and Scripting

redirect STDOUT to a file in a subshell

Hi, I would like to avoid re-directing line by line to a file. What is the best way to re-direct STDOUT to a file in a subshell? Thanks in advance. Cheers Vj (1 Reply)
Discussion started by: tnvee
1 Replies

10. Shell Programming and Scripting

Subshell Question

The profile of the user is empty. Then before I run the script I want I run a parameter file that populates the variables for oracle. ORACLE_HOME ORACLE_BASE ORACLE_SID PATH etc ... But it seems that these variables are not making it to the shell I am in because when I do an echo on... (6 Replies)
Discussion started by: lesstjm
6 Replies
Login or Register to Ask a Question