How to send data to previous program (pipe)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to send data to previous program (pipe)?
# 1  
Old 02-05-2018
Hammer & Screwdriver How to send data to previous program (pipe)?

Hi,
Suppose I have a command:
Code:
$ cmd1 | cmd2

I need to send a message from cmd2 to cmd1 when I receive some a certain message from cmd1. How to do this?
I think that I have to know cmd1's PID and then in cmd2 send a message to this PID. How?
# 2  
Old 02-05-2018
The second process, cmd2, will be able to read the standard output from cmd1 You should not need to know the PID.

It's all a bit theoretical at the moment. Can you explain what you really want to achieve?


Something like ls -l | more is a simple example of this. The output from ls -l (excluding errors) is passed to more which displays the output, pausing with a prompt when it believes it has written a screenful. The shell transfers the input for the more to be reading from the output of the ls rather than from the keyboard or whatever else standard input is defined as.


I'm sure we can explain this with a better example of what you are trying to do overall.



Kind regards,
Robin
# 3  
Old 02-05-2018
Hi Robin,
JackK knows cmd2 can read data from cmd1. He wants to know how cmd1 can also read data from cmd2.

Hi JackK,
Send email to yourself, send a message to a message queue, write to a regular file, write to a FIFO file, send a signal, write some text into a shared memory segment... There are hundreds of ways to do this.

What shell are you using?

What operating system are you using?

What is the format of this message you want to send?

What are these two processes doing besides sending data to each other with a pipe being used for sending messages between the two processes in one direction?

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 02-05-2018
Hi Don Cragun,
This is not a homework. I need this because there is no automatic way to have PDB database name visible in SQL*Plus sqlprompt. I saw a solution by using a dedicated SQL function to change current container but this is not what I want to use.

I created a parse-function which I use like this:
Code:
$ sqlplus user@DB | parsefunc

This function is looking for some patterns in input data and do some text highlights. I'd like to add an option to send a command to sqlplus:
Code:
set sqlprompt "_user'@'_connect_identifier::<PDBname> SQL> "

when user execute a command similar to
Quote:
alter session set container = <PDBname>;
This is to make a work in our team easier.

We are using RHEL. Shell is Bash. Company is IBM.

Last edited by JackK; 02-05-2018 at 08:13 AM..
# 5  
Old 02-05-2018
Maybe you should connect the two commands not via a (one-directional) pipe, but use something like "expect" to drive the SQL shell: Manpage of EXPECT

You would have to learn some Tcl, but the language is easy.
# 6  
Old 02-05-2018
Hi rovf,
I think, using Expect for this is not needed and hard. I have no idea at the moment, how could I achieve this this Expect.
I am sure there is an easier way to fulfill my needs. There should be some way to get a PID of sqlplus (cmd1) inside parsefunc (cmd2) and send a string (command) to sqlplus's input using its PID, shouldn't it?
# 7  
Old 02-05-2018
Not within a shell redirection, i.e. a pipe, if you want to retain the stdin from terminal. You would need to rebuild both commands to enable them to read from and / or write to additional file descriptors and create the channels (pipes?) for that.
How about saving above pipe's result into a file and feed that into cmd1 in another (new!) process?

Last edited by RudiC; 02-05-2018 at 12:02 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

RWSocket::send: Broken pipe Error in /var/adm/messages

Hi Guys, I am getting some strange error in /var/adm/messages in my Solaris 10 box with Veritas Cluster and EMC storage. bash-3.00$ cat /var/adm/messages | egrep -v "lw8|snmp|sshd|xntpd|kern.info|LOGIN|link|service|started|finished|repeated|SS7 Log-daemon|success" Dec 18 09:58:35 GAMMa2... (1 Reply)
Discussion started by: vivek.goel.piet
1 Replies

2. Shell Programming and Scripting

Perl to send previous and current value

For example, I have a file called number.txt. x y 1 1 2 4 3 9 4 6 5 5 6 6 7 9 8 4 9 1 10 0 ... And I want to print out the value of x and y, if y%4==0 and the next value of y%4==0. Thus, the sample output is: 1 1 *because the previous x before 2 is 1 2 4 *because 4%4 == 0 7 9... (2 Replies)
Discussion started by: Tzeronone
2 Replies

3. Linux

Perl program to print previous set of lines once a pattern is matched

Hi all, I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in... (2 Replies)
Discussion started by: kaav06
2 Replies

4. UNIX for Advanced & Expert Users

sftp error:- Couldn't send packet: Broken pipe

Hi, I am trying to sftp a large file(appx. 2 GB size) from solaris 10 to a Linux server. While sftping(with no options), connection is terminated after some time with broken pipe error. sftp with option -R1 or -B1500 is successful. Linux server ssh Version: OpenSSH_3.9p1, OpenSSL 0.9.7a... (3 Replies)
Discussion started by: brij123
3 Replies

5. Homework & Coursework Questions

pipe program in C

Hello guys, my professor give me 2 days to study and make a program usign pipe, fork in c i need to do a program read a arq.txt the father process read the file and the child print ! 2. Relevant commands, code, scripts, algorithms: like this Code: #include <stdio.h>... (1 Reply)
Discussion started by: beandj
1 Replies

6. Programming

pipe program in C

Hello guys, my professor give me 2 days to study and make a program usign pipe, fork in c i need to do a program read a arq.txt the father process read the file and the child print ! like this #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> int main (){ ... (1 Reply)
Discussion started by: beandj
1 Replies

7. Solaris

sendmail pipe to a program.

Hello, I recently upgraded our server from Solaris 8 to 9. The sendmail is unabled to pipe the email to a perl script. I can send and received email to local and external mail, but the script did not get the email. There is no error in the log and I could not find any thing on the web. Here... (0 Replies)
Discussion started by: ld98
0 Replies

8. Shell Programming and Scripting

Writing a program to receive the GPS data and send to other server

Hi, I would like to write a program to receive the GPS data and then send the data via network to other program. All of the program is not write yet(include host and sender) All of the server OS is unix or linux Could you mind to give me some idea to do this? Thanks so much! Ken ... (2 Replies)
Discussion started by: kenlok
2 Replies

9. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

10. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies
Login or Register to Ask a Question