Sponsored Content
Top Forums Shell Programming and Scripting ret val of a command in a pipe which is NOT the last one Post 30901 by Perderabo on Tuesday 29th of October 2002 10:40:52 AM
Old 10-29-2002
I don't understand why you are invoking an explicit subshell here, nor why you would use "ksh -c" to invoke it. I'm guessing that you don't want to change the script's current definition of LIBPATH. Assuming that to be an absolute requirement, you can do this:

exec 4>&1 5>&2
tee -a ${LogFile} >&4 |&
exec >&p 2>&1
(export LIBPATH=$X ; eval exec ${Cmd} ${param})
RET=$?
exec >&4 2>&5
echo RET = $RET

This is perhaps even more convoluted than your work-around. But it eliminates that "tail -f" and returns to the "tee" command. And it also eliminates the race condition from your sleep/kill commands. If the subshell is not needed, you should replace it with:
export LIBPATH=$X
eval ${Cmd} ${param}
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to pipe command

Hi All, I want to create a command that executes a text editor with the most recent file in the current current directory. So a good start to achieve this is : ls -lrt | cut -c55- | tail -1 which provides the name of the most recent file in a directory The problem is to pipe the... (4 Replies)
Discussion started by: anonymous.nico
4 Replies

2. UNIX for Dummies Questions & Answers

pipe command

current dir : /home/sales ls -l abc.txt 17th aug bcd .txt 16t oct ------- ------ Total files : 100 if i want to move only those files dated 17 aug into another sub directory /home/sales/texas how do i pipe the result of 'ls' command to a 'mv' command (1 Reply)
Discussion started by: zomboo
1 Replies

3. Programming

Capturing a ret val of C obj file in ksh script

Hi, I have one shell script which is calling a C executable. That C executable returns a value depending upon operations inside the C code. But how to get that value in the calling shell script? The syntax of calling the C executable is like -- C_exec <argc no> <argument1> <argument2> etc... (5 Replies)
Discussion started by: k_bijitesh
5 Replies

4. Shell Programming and Scripting

vmstat returns good val for cpuIdle put ps shows no active process

hi i'm running a shell script that checks the amount of cpu idle either using /usr/bin/vmstat 1 2 or sar 1 2 (on unixware) before i run some tests(if cpu idle greater than 89 I run them). These tests are run on many platforms, linux(suse, redhat) hp-ux, unixware, aix, solaris, tru64. ... (5 Replies)
Discussion started by: OFFSIHR
5 Replies

5. UNIX for Dummies Questions & Answers

How can I use pipe command ?

Hi My friends I have used this command to find files are modified within the past 24 hours and then many files are shown but I want transfer all these files to special directory by using pipe . can any one tell me what is the next step ? (11 Replies)
Discussion started by: bintaleb
11 Replies

6. Shell Programming and Scripting

pipe grep command

Hi all, Can someone help me with the following problem. I am executing the following command: (search for occurences of 'error' in files that match cl-*.log expression) > grep -cw -i --max-count=1 'error' cl-*.log this command outputs: cl-apache.log:1 cl-apache_error.log:1... (3 Replies)
Discussion started by: epro66
3 Replies

7. Shell Programming and Scripting

pipe in command

Hello, I try to concatenate a command to execute. Sadly it throws an error. #!/bin/bash cd / cmd="find -name *.txt | awk '{ printf "FILE: "$1; system("less "$1);}' | egrep 'FILE:|$1'" echo "1." $($cmd) echo "2." $("$cmd") echo "3." `$cmd` echo "4." `"$cmd"`1.&3. 'find: paths must... (2 Replies)
Discussion started by: daWonderer
2 Replies

8. Shell Programming and Scripting

Single command pipe

Single command to ls all the files inside a particular directory hierachy and output this to a file and open this in a vim file so that i can use gf command in vim to browse through all the files inside this hierachy. eg : dir1/dir2 and dir1/dir3 dir2 and dir3 contain the files i need... (7 Replies)
Discussion started by: dll_fpga
7 Replies

9. Shell Programming and Scripting

Capture a database val and use in script

Hello, sorry if this has been asked before, I couldn't find what I was looking for. I know how to connect to Oracle and execute stored procedures from a shell script, but what I would like to do is return a value from a table and use it in my script. For Example, If I had a table Called... (1 Reply)
Discussion started by: mode09
1 Replies

10. Shell Programming and Scripting

Stripping ret of the lines in a file (sed question)

Hi all, I didn't use SED for 20 years and was never an expert. So my current knowledge is about zero. Please be patient with me. I'm neither a native speaker. I have a huge dictionary file and want the rest of the lines stripped. Everything after (and including) the "/" should be stripped. I... (2 Replies)
Discussion started by: Hinnerk2005
2 Replies
popen(3S)																 popen(3S)

NAME
popen(), pclose() - initiate pipe I/O to/from a process SYNOPSIS
DESCRIPTION
creates a pipe between the calling program and a command to be executed by the POSIX shell, (see sh-posix(1)). The arguments to are pointers to null-terminated strings containing, respectively, a shell command line and an I/O mode, either for reading or for writing. returns a stream pointer such that one can write to the standard input of the command if the I/O mode is by writing to the file stream; and one can read from the standard output of the command if the I/O mode is by reading from the file stream. Because open files are shared, a type command can be used as an input filter and a type command as an output filter. If mode is other than or the result is undefined. A stream opened by should be closed by which waits for the associated process to terminate and returns the exit status of the command. However, if a call caused the termination status to be unavailable to then returns -1 with errno set to This can happen in one of the fol- lowing conditions: o If the signal handler for is set to o If the signal handler or another thread in the same process issues or call. APPLICATION USAGE
After a stream is associated with a pipe by the stream is byte-oriented (see orientation(5)). RETURN VALUE
Upon successful completion, returns a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it returns a NULL pointer if files or processes cannot be created and set errno to indicate the error. The success of the command execution can be checked by examining the return value of Upon successful return, returns the termination status of the command language interpreter. Otherwise, returns -1 if stream is not associ- ated with a command and set errno to indicate the error. ERRORS
The function fails if: The maximum number of file descriptors allowed are currently open. The function fails if: The status of the child process is not available. WARNINGS
If the original and processes concurrently read or write a common file, neither should use buffered I/O because the buffering will not work properly. Problems with an output filter can be forestalled by careful buffer flushing, e.g., with see fclose(3S). SEE ALSO
pipe(2), wait(2), fclose(3S), fopen(3S), system(3S), orientation(5), thread_safety(5). STANDARDS CONFORMANCE
popen(3S)
All times are GMT -4. The time now is 08:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy