Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-03-2013, 11:37 AM   #1
LQ Newbie
Registered: Nov 2013
Posts: 2

Rep: Reputation: Disabled
Bash script exits halfway ?

I have a bash script . thus:

#!/usr/bin/env bash
set -x

echo "Getting Radio Station IDs ..."
grep "<station name=" stations.xml | sed 's_\&amp;_\&_' | sed 's/<station name=".*" id="//' | sed 's/" br=".*ion>//' >stnID.txt

echo "Getting Radio Station Names ..."
grep "<station name=" stations.xml | sed 's_\&amp;_\&_' | sed 's/<station name="//' | sed 's/\" mt=".*ion>//' >stnList.txt
What the lines do is not important ...(actually it extracts 2 lists from an xml file and saves to 2 separate txt files).

The script works perfectly when I type:


from the prompt.

Now I execute this script from a C program using popen.

When I do this, only the 1st grep command is executed. The 2nd grep line is never executed.

To repeat, the script works as intended when typed at the prompt, but not when called from an application.

Any help would be appreciated ! Thanks.
Old 11-03-2013, 05:38 PM   #2
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,704

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
I think it is going to depend on the C program. What is the code for reading the input from popen?
Old 11-04-2013, 01:53 AM   #3
LQ Newbie
Registered: Nov 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Solved !

jpollard ,

Thanks for replying... yes you were right ...
I was closing popen prematurely, before the script finished, based on a time delay.
Now I check if the script has actually finished then I pclose
and it works.

Thank You.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How this bash works? - Terminating openbox when the app exits? deckoff Programming 3 05-29-2012 01:05 AM
bash - setting a persistent variable that remains after the script exits CJ Chitwood Programming 9 01-24-2009 07:48 PM
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 03:07 AM
script exits tostay2003 Programming 4 12-26-2007 08:13 AM
Flagging exits in Bash Script dtheorem Programming 5 11-08-2003 10:15 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration