LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 11:37 AM   #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, 05:38 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 PM.

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
Open Source Consulting | Domain Registration