LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-03-2013, 12:37 PM   #1
roycejp
LQ Newbie
 
Registered: Nov 2013
Posts: 2

Rep: Reputation: Disabled
Bash script exits halfway ?


Hi,
I have a bash script . getStnList.sh thus:

Code:
#!/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:

./getStnList.sh

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, 06:38 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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, 02:53 AM   #3
roycejp
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.
 
  


Reply


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 02:05 AM
bash - setting a persistent variable that remains after the script exits CJ Chitwood Programming 9 01-24-2009 08:48 PM
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 04:07 AM
script exits tostay2003 Programming 4 12-26-2007 09:13 AM
Flagging exits in Bash Script dtheorem Programming 5 11-08-2003 11:15 PM


All times are GMT -5. The time now is 03:01 AM.

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