BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 23rd, 2009, 05:59 PM
fubes2000's Avatar
fubes2000 fubes2000 is offline
manwich
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2003
Location: Canadanistan
Posts: 575 fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)fubes2000 User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 444419 Folding Title: Super Ultimate Folder - Level 1Folding Points: 444419 Folding Title: Super Ultimate Folder - Level 1Folding Points: 444419 Folding Title: Super Ultimate Folder - Level 1Folding Points: 444419 Folding Title: Super Ultimate Folder - Level 1Folding Points: 444419 Folding Title: Super Ultimate Folder - Level 1Folding Points: 444419 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 10 h 47 m
Reputation Power: 383
Hang on redirecting stderr to named pipe

I'm working on a script to handle some basic mySQL statements, but I need it to be aware of whether or not the statement that was just executed contained an error. Since mySQL prints it's error messages to stderr and exits with status code 0 a little bit of finagling is in order.

The below function takes a mySQL query as a single argument, printing the results as a comma-delimited list, and it worked just fine until I added '2> $err_pipe' and related code. $err_pipe being the named pipe which is created earlier.

Code:
function pf_query {
    if [ $# -ne 1 ]; then
        echo "-- mySQL function error: invalid arguments for query" >&2
        return 1
    else
        mysql -h $pf_h -u $pf_u -p$pf_p -D $pf_d -B -e "$1" --skip-column-names 2> $err_pipe | tr -d ',' | tr "\t" ","
        q_error=`cat $err_pipe`
        if [ -n "$q_error" ]; then
            echo "-- mySQL Errors: $q_error" >&2
            return 1
        else
            return 0
        fi
    fi
}
The truly odd thing is this code seemed to work until I added some code to check if the pipe is created properly prior to the execution of the function:
Code:
err_pipe=/home/user/bin/_include/err_pf
if [ -e $err_pipe ]; then
    echo "pipe exists" >&2
    if [ ! -p $err_pipe ]; then
        echo "Error pipe is not a pipe, re-creating" >&2
        rm $err_pipe
        mkfifo $err_pipe
    else
        echo "pipe is a-ok" >&2
    fi
else
    echo "no pipe, creating." >&2
    mkfifo $err_pipe
fi
With the code as above the script hangs, I believe due to an unconnected pipe. If I add a & to the line with the mysql statement the script completes, but with informational garbage in both stdout and stderr from the backgrounding of the command, ie:
Code:
[2]-  Done                    mysql -h $pf_h -u $pf_u -p$pf_p -D $pf_d -B -e "$1" --skip-column-names 2> $err_pipe | tr -d ',' | tr "\t" ","
Is put into my output, which is not acceptable to the functions that will be using this function.

Admittedly I am not as familiar with named pipes as I would like to be, could someone please point me in the direction of getting this issue resolved?
__________________

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > Hang on redirecting stderr to named pipe

Developer Shed Advertisers and Affiliates



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap