Multiple co-processor file descriptors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple co-processor file descriptors
# 1  
Old 03-01-2005
Question Multiple co-processor file descriptors

I have a script that creates a KSH co-process for Oracle sqlplus and I am presently interacting with it via print -p and read -p.

I also need to interact with another Oracle database what isn't permitted to have any direct connection to the first. Presently, I simply disconnect from the first database, connect to the second database, and reconnect to the first database when I am finished, again using print -p and read -p.

I would like to enhance this a bit using a second co-process. I know how to create the second sqlplus co-process by first redirecting stdout and stdin for the first co-process using exec fd>&p and exec fd<&p. Then I can create the second co-process and interact with both.

My desire is to write a db_connect function that is capable of determining that a co-process has already been started and a new co-process with new file descriptors needs to be started. Along with this, I would like to dynamically determine which co-process to communicate to using generalized functions.

Any thoughts? Can the open file descriptors be tested? The version of KSH is KSH-88 I believe.

Thomas
# 2  
Old 03-01-2005
The only thing I can think of is to create a global variable and increment it for each co-process. The test on a fd that I know of is
[ -t $fd ]
which checks for being a tty.
# 3  
Old 03-02-2005
Thanks for the suggestion with regards to using a global variable. I am not opposed to doing this. I hope that it doesn't get lost on the poor DBAs here who will have to maintain these scripts when I eventually have to move on.

I started working on a proof of concept and hit an unexpected snag using eval. My thought is that I would pass a handle (just a string really) to my database functions and build variables based on the handle. When I try to redirect stdout and stdin to some open file descriptors, I get an error.

Code:
#!/usr/bin/ksh

sqlplus -s /nolog |&

x=TESTVAR

eval export ${x}_stdout=3
eval export ${x}_stdin=4

eval print $TESTVAR_stdout
eval print $TESTVAR_stdin

eval exec ${TESTVAR_stdout}>&p
eval exec ${TESTVAR_stdin}<&p

eval print -u $TESTVAR_stdout "PROMPT Hello"
eval read -u $TESTVAR_stdin LINE

print $LINE

eval exec ${TESTVAR_stdout}>&p <==== results in "t[13]: 3: not found"

The previous lines work fine, I am scratching my head on why TESTVAR_stdout isn't expanding properly.

What is more perplexing is If I manually execute the lines with numeric literals, it works. If I manually execute the lines using variable and no "eval", KSH indicates that I have running jobs for stdout and closes my session for stdin.

If I can get past this hurdle, I can implement the concept easily.

Thomas
# 4  
Old 03-02-2005
Computer I think I may have it

I may have figured out my problem so I am posting an update if anyone is interested.

Code:
#!/usr/bin/ksh

sqlplus -s /nolog |&

x=TESTVAR

eval export ${x}_stdout=3
eval export ${x}_stdin=4

eval print $TESTVAR_stdout
eval print $TESTVAR_stdin

eval "exec ${TESTVAR_stdout}>&p"
eval "exec ${TESTVAR_stdin}<&p"

eval "print -u${TESTVAR_stdout} \"PROMPT Hello\""
eval "read -u${TESTVAR_stdin} LINE"

print "From sqlplus: $LINE"

My "eval" expressions needed to be inside quotation marks.

Thomas
# 5  
Old 03-02-2005
Network

Sorry, I am not trying to bump up my post but I wanted to retract my previous post as the solution only works when I name my variables. I realized that I wasn't referencing my dynamic variable "x". I am still scratching my head...

Thomas
# 6  
Old 03-02-2005
Sorry, again, I am not trying to bump anything up, I have a core issue, that I am trying to narrow this thread's scope to focus on, using "eval" that is eluding me so if I can get past this, my problem is solved.

Essentially my "x" variable should be able to translate into another variable containing my file descriptor. If I can get "x" to expand into TEXTVAR2_stdout and then expand this so that "4" can be assigned to a local function variable, I am golden.

Code:
#!/usr/bin/ksh

sqlplus -s /nolog |&

x=TESTVAR2

eval export "${x}_stdout=3"
eval export "${x}_stdin=4"

# Print using named variables
print $TESTVAR2_stdout
print $TESTVAR2_stdin

# Same thing attempting expansion of my "x" variable;
# results in print TESTVAR2_stdout but no 4
eval "print ${x}_stdout"
# results in print $TESTVAR2_stdout
print $(expr $"${x}_stdout")

I get down to something that looks like $TESTVAR2_stdout but I cannot get the shell to treat it as a variable.

Thomas
# 7  
Old 03-02-2005
Code:
#!/bin/ksh

x=TESTVAR2

eval export "${x}_stdout=3"

print $TESTVAR2_stdout

# results in print $TESTVAR2_stdout
eval "print \$${x}_stdout"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Questions about file descriptors

Hi, I'm playing with KSH I entered following command in terminal { echo "stdout" >&1; echo "stderr" >&2; } > out And I get only stoud in a new file out. My question is: Where did my stderr vanish ? (5 Replies)
Discussion started by: solaris_user
5 Replies

2. UNIX for Dummies Questions & Answers

Semaphores and File Descriptors

What is the difference between a file descriptor and a semaphore? My basic understanding is: - a file descriptor is a small positive integer that the system uses instead of the file name to identify an open file or socket. - a semaphore is a variable with a value that indicates the... (1 Reply)
Discussion started by: Mr_Webster
1 Replies

3. HP-UX

exec and file descriptors

Hi, I speak and write english more or less, so I hope my asking be clear. :) In the company I am working, they are using control-m software to lunch shell scripts. So i put this command in all shell scripts: export LOGFILE_tmp=$PRODUC_DATA/tmp/${SCRIPT}_${PAIS}_`date... (0 Replies)
Discussion started by: anamcara
0 Replies

4. UNIX for Dummies Questions & Answers

Write/read to file descriptors

Is it possible to write to file descriptor 0 and read from 1 or 2? How could this be implemented? (3 Replies)
Discussion started by: machshev
3 Replies

5. UNIX for Advanced & Expert Users

File Descriptors + cron

Hi All, This thread is going to be a discussion basically bringing out more information from the experts on cron jobs and the associated file handles. So, here is the question. There is definitely a constant ' n ' as the maximum number of file handles alloted to a process ' p '. Will... (7 Replies)
Discussion started by: matrixmadhan
7 Replies

6. UNIX for Advanced & Expert Users

File descriptors missing on startup

Dec 20 15:34:32 hostname sendmail: File descriptors missing on startup: stderr; Bad file number Dec 20 15:34:32 hostname sendmail: File descriptors missing on startup: stderr; Bad file number Dec 20 15:34:32 hostname sendmail: File descriptors missing on startup: stderr; Bad file number Dec... (1 Reply)
Discussion started by: xnightcrawl
1 Replies

7. Programming

Sockets and File descriptors

I am in a Systems programming class this semester, and our current project is to write a program utilizing sockets and fork. For the project, I decided to make my own instant messaging program. I have the code completed, but I have a problem that keeps old clients from communicating with new... (3 Replies)
Discussion started by: gstlouis
3 Replies

8. UNIX for Dummies Questions & Answers

file descriptors

i m trying to learn processes in unix and i've been reading this but i don't quite get it. its regarding file descriptors. : each is a part of file pointers, they point to another area. indexes into an Operating system maintained table called "file descriptor table". one table per process. may... (3 Replies)
Discussion started by: a25khan
3 Replies

9. UNIX for Advanced & Expert Users

File Descriptors

Hello all, A few questions on file descriptors ... scenario : Sun Ultra 30 with Sun OS 5.5.1 , E250 with Solaris 2.6 In one of my servers, the file descriptor status from the soft limit and hard limits are 64 and 1024 respectively for root user. Is the soft limit (64) represents the... (3 Replies)
Discussion started by: shibz
3 Replies

10. Programming

File Descriptors

Hi, I have written a daemon process, to perform certain operations in the background. For this I have to close, the open file descriptors, Does anybody know how to find out the number of open file descriptors ? Thanks in Advance, Sheetal (2 Replies)
Discussion started by: s_chordia
2 Replies
Login or Register to Ask a Question