The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File Descriptors + cron matrixmadhan UNIX for Advanced & Expert Users 7 05-23-2007 01:53 PM
Sockets and File descriptors gstlouis High Level Programming 3 12-12-2005 07:36 AM
file descriptors a25khan UNIX for Dummies Questions & Answers 3 01-27-2004 07:46 PM
File Descriptors shibz UNIX for Advanced & Expert Users 3 12-18-2002 10:12 AM
File Descriptors s_chordia High Level Programming 2 12-24-2001 11:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-24-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
File descriptors problem perplexing me

Greetings,

I have a troubling problem with a Korn Shell concept that I know works in Solaris.

Essentially I am assigning file descriptors to a coprocess. Also, it should be noted that I am not using the public domain ksh but, rather AT&T ksh93.

Here is a test scenario:

$ sqlplus -s /nolog |& <== Coprocess
[1] 8566
$ print -p "prompt Hello"
$ read -p line
$ print $line
Hello <== proof that the async communication works


$ exec 5>&p <== assign fd 5 to stdout and fd 6 to stdin
$ exec 6<&p
$ print -u5 "prompt Hello again" <== This works in Solaris but not in Linux
ksh: print: bad file unit number <== I don't know why this is occurring
[1] + Done sqlplus -s /nolog |& <== coprocess dies
$ read -u6 line
$ print $line

$ ulimit -a
address space limit (kbytes) (-M) unlimited
core file size (blocks) (-c) 0
cpu time (seconds) (-t) unlimited
data size (kbytes) (-d) unlimited
file size (blocks) (-f) unlimited
locks (-L) unlimited
locked address space (kbytes) (-l) 32
nofile (-n) 65536 <== Should be enough fds available
nproc (-u) 16384
pipe buffer size (bytes) (-p) 4096
resident set size (kbytes) (-m) unlimited
socket buffer size (bytes) (-b) 4096
stack size (kbytes) (-s) 10240
threads (-T) not supported
process size (kbytes) (-v) unlimited

Any ideas why I can't do this in Linux?

Regards,

Thomas
  #2 (permalink)  
Old 01-24-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
What you're doing looks good to me. I would suspect a bug your linux version of ksh.
  #3 (permalink)  
Old 01-24-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by Perderabo
I would suspect a bug your linux version of ksh.
I downloaded and manually installed the latest binary version of KSH from AT&T Research Labs. I thought about downloading and compiling the source. I'll give that a try as soon as I can. I was really hoping that someone had experienced something similar and knew the magic kernel parameter. Thanks for the comments.

Thomas
  #4 (permalink)  
Old 01-24-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
And if that doesn't work try pdksh - I'm running v5.2.14 99/07/13.2 and the example you posted works fine for me.

Cheers
ZB
  #5 (permalink)  
Old 01-24-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by zazzybob
And if that doesn't work try pdksh - I'm running v5.2.14 99/07/13.2 and the example you posted works fine for me.
I already confirmed prior to posting that pdksh does work fine as you have indicated (even on a PC running CYGWIN). The problem that I encountered with pdksh has to do with variable scope as follows:

$ set -A RESULTS_ARRAY "Initial Value" 0 0 0 0
...
$ {
... some command producing output...
} | while read LINE
> do
> ...
> RESULTS_ARRAY[0]="Some new text"
> RESULTS_ARRAY[1]=1
> ...
> done

$ print ${RESULTS_ARRAY[0]}
Initial Value

The variable's scope appears to be limited to within the while loop. This is probably basic but I could not determine the answer at 2 AM when I was struggling over it. This is when I discovered that I had been using pdksh rather than AT&T's. AT&T's corrected this and I quit persuing it. What technique do I use to broaden the variable's scope? I tried to export the variable with the same results.

Thomas
  #6 (permalink)  
Old 01-26-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by tmarikle
...The problem that I encountered with pdksh has to do with variable scope as follows:...
...What technique do I use to broaden the variable's scope?....
At least I found why pdksh behaves they way I described. When piping through "while read" loop, everything inside the loop is executed in a subshell. This why my variables were not taking hold.

It may be easier to alter my code to avoide "while read" loops and go back to pdksh than to figure out my file descriptor problem.

Thomas
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0