LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script exits halfway ? (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-exits-halfway-4175483254/)

roycejp 11-03-2013 11:37 AM

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.

jpollard 11-03-2013 05:38 PM

I think it is going to depend on the C program. What is the code for reading the input from popen?

roycejp 11-04-2013 01:53 AM

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.


All times are GMT -5. The time now is 08:13 PM.