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

Hash: SHA1

Christopher Faylor wrote:
| On Thu, Dec 16, 2004 at 03:29:16PM -0500, 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
|>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.
| Just to demonstrate what you're seeing without the sqlplus requirement:
|   bash$ echo hello | read line
|   bash$ echo $line
|   bash$
| The reason for the behavior is apparently that when you use read in a
| pipe like this bash and ash fork a separate process so the variable only
| exists very briefly in that process and `line' is never defined in the
| main process.
| zsh does what you'd expect, so if you can use zsh instead of bash, that
| would be a solution.  Otherwise, you probably will have to experiment
| with setting IFS and using either $(sqlplus) or `sqlplus` .
| cgf

Actually I'm using ksh.

$ echo hello | read LINE
$ echo $LINE


Looks like you said. I know this is not the expectd behaviour for ksh
though. On Solaris ksh ...

Solaris$ echo hello | read LINE
Solaris$ echo $LINE

Why would ksh behave differently under Cygwin than under Solaris?

-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (MingW32) Comment: Using GnuPG with Thunderbird -


-- Unsubscribe info: Problem reports: Documentation: FAQ:

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