This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Piping output from sqlplus

At Thursday, December 16, 2004 3:57 PM, Chuck wrote:
> Buchbinder, Barry (NIH/NIAID) wrote:
>> At Thursday, December 16, 2004 3:29 PM, Chuck wrote:
>>> I'm having a strange problem reading the output from sqlplus in
>>> Cygwin. Sqlplus is a windows command line program used to access
>>> oracle databases. My command looks something like this...
>>> sqlplus -s <<! | read line
>>> user/password@database
>>> set pagesize 0 linesize 200 feedback off tab off
>>> select col1||chr(9)||col2
>>> from table;
>>> !
>>> This should output one line to stdout with the two values separated
>>> by a tab character. The read command should read it into the
>>> variable $line. On my Solaris system it works perfectly. In Cygwin,
>>> $line is empty. 
>>> If I remove the "read line", the output displays on the tty just
>>> fine. 
>>> I though it might be related to the line end characters so I tried
>>> converting them with the dos2unix filter. Didn't work. Neither did
>>> tr -d \\r. Both ways, $line still ends up being empty.
>>> If I replace the "read line" with "od -c" to dump the characters, it
>>> shows the one line as expected.
>>> If I redirect the output to a file, the file contains one line as
>>> expected. 
>>> If I try to read the output into a variable, I get an empty variable
>>> Any ideas?
>> If the output shows up OK in a file, do
>> VAR="$(cat file)"
> That may work but it misses the point. I'm writing a script and I want
> it to work on Cygwin and unix.
> BTW the shell I'm using is ksh.

Well, I don't have access to a Unix or Linux machine, but I would have
thought outputting a file and filing the variable by cat'ting it would work
there, too.

I don't use ksh.  If what I suggested does not work there, something like
the following should.

VAR=`cat file`

If the trailing \n gets converted into an undesirable space, you could
always do

VAR=`cat file | tr -d '\n'`

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]