aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2012-03-30 00:05:57 +0000
committerdrh <drh@noemail.net>2012-03-30 00:05:57 +0000
commite1da8fadcc2ded2a17f3675a7837b55b4bd52c0b (patch)
tree551f3c1000e2b3460041ae553ddadaa107eefc5d /src
parent4e245a4c35fd2e34923f1cf047cbd74f5b67273e (diff)
downloadsqlite-e1da8fadcc2ded2a17f3675a7837b55b4bd52c0b.tar.gz
sqlite-e1da8fadcc2ded2a17f3675a7837b55b4bd52c0b.zip
In the ".output" command-line shell, if the first character of the output
filename is '|' then use popen() instead of fopen(). FossilOrigin-Name: fa82062c659ffbe7ad01106d3ef54d7bb44f1f44
Diffstat (limited to 'src')
-rw-r--r--src/shell.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/shell.c b/src/shell.c
index 52b5c4227..4287ef17d 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -68,6 +68,8 @@
# include <io.h>
#define isatty(h) _isatty(h)
#define access(f,m) _access((f),(m))
+#define popen(a,b) _popen((a),(b))
+#define pclose(x) _pclose(x)
#else
/* Make sure isatty() has a prototype.
*/
@@ -1999,11 +2001,24 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
if( p->out!=stdout ){
- fclose(p->out);
+ if( p->outfile[0]=='|' ){
+ pclose(p->out);
+ }else{
+ fclose(p->out);
+ }
}
if( strcmp(azArg[1],"stdout")==0 ){
p->out = stdout;
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "stdout");
+ }else if( azArg[1][0]=='|' ){
+ p->out = popen(&azArg[1][1], "w");
+ if( p->out==0 ){
+ fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]);
+ p->out = stdout;
+ rc = 1;
+ }else{
+ sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
+ }
}else{
p->out = fopen(azArg[1], "wb");
if( p->out==0 ){