2
out="$katalog/out" # wyjscie
fifo="$katalog/fifo" # wejscie
mkfifo $fifo 
touch $out
[...] #k
./a.out <$fifo >$out & pid=$!
[...] # get input line by line loop start
echo "$liniain" >> $fifo    
[...] # loop end

I try this but after first input line to program script stop and don't respons

Complete script

#!/bin/bash
#Debuger programow w c ++
katalog="/tmp/debuger$$"
mkdir $katalog # katalog tymczasowy z danymi
out="$katalog/out" # wyjcie
fifo="$katalog/fifo" # wejscie
mkfifo $fifo # nawet powstalo (potok nazwany)
touch $out
if [ -n $0 ] ; then echo "podaj -h"
fi
while getopts hvar opt ; do
    case $opt in
    h) echo "Script prowadzi za raczke -r reset ustawien -a autor ";;
    v) echo "--wersja---";;
    a) echo "Jakub Staniszewski";;
    r) rm ./debug.cfg;;
    *) echo "nie rozumiem";;
    esac
done

if [ ! -e ./debug.cfg ] ; then
    dialog --title "PLIKI IN"  --fselect ./ 10 40 2>$katalog/dial 
    pliki_in=$(<$katalog/dial)
    dialog --title "PLIKI OUT"  --fselect ./ 10 40 2>$katalog/dial 
    pliki_out=$(<$katalog/dial)
    dialog --title "CO SKOMPILOWAC"  --fselect ./ 10 40 2>$katalog/dial 
    plik_compile=$(<$katalog/dial)  
    dialog --title "Opcje_kompilatora" --inputbox "Podaj Nazwe pliku wykonywalnego" 8 40 "a.out" 2> $katalog/dial 
    program=$(<$katalog/dial)
    dialog --title "Opcje_kompilatora" --inputbox "Podaj opcje cd" 8 40 "" 2> $katalog/dial 
    flagi=$(<$katalog/dial)
    dialog --title "Polecenie do debugowania" --inputbox "Podaj polecenie do debugowania" 8 40 "debug" 2> $katalog/dial 
    debugpolecenie=$(<$katalog/dial)
    echo "pliki_in=$pliki_in" > ./debug.cfg
    echo "pliki_out=$pliki_out" >> ./debug.cfg
    echo "plik_compile=$plik_compile" >> ./debug.cfg
    echo "program=$program" >> ./debug.cfg
    echo "flagi=$flagi" >> ./debug.cfg
    echo "debugpolecenie=$debugpolecenie" >> ./debug.cfg

fi

. debug.cfg
g++ $plik_compile -o $program $flagi
find $pliki_in | grep .in$ | sort -u > $katalog/lista.in
find $pliki_out | grep .out$ | sort -u > $katalog/lista.out
for in_plik in `cat $katalog/lista.in` ; do #przez wszystkie pliki in
    ./$program <$fifo >$out & pid=$! #odpalam program
    nazwa_in=`echo "$in_plik" | sed 's/\// /g'|awk '{ print $(NF) } '| sed 's/.in$//g'` # wyciagam nazwe np ./testy/12.in da 12
    outtest=`cat ${katalog}/lista.out| grep /${nazwa_in}.out$` # wybieram plik z odpowiedziami
    echo $outtest 
    przeczytane=1 # o jeden wiecej niz liczba lini ktore zostaly przeczytane z pliku in
    wyjscie=1 # o jeden wiecej niz liczba lini sprawdzonych  ( plik *.out)
    for liniain in `cat $in_plik`; do
        if ps -aux 2>/dev/null |awk '{ print $2 }'| grep $pid  ; then   echo "$liniain" >> $fifo #czy nasz program dziala   
        else 
            echo "cos zdechlo"
            break
        fi
        for linia in `tail -n +$przeczytane $out` ; do 
            liniatest=`cat $outtest | head -n$wyjscie | tail -n1`
            echo "$liniatest"
            if [ "$linia" = "$liniatest" ] ; then  true #echo "$linia"
            else
                echo " Powinno byc:  `cat $outtest | head -n $wyjscie | tail -n1` "
                echo " a jest :$linia"  
                echo "$debugpolecenie" > $fifo #2>/dev/null
                echo "-+-+-=_=="
                tail -n +$przeczytane $out
                q="t"
                break 
            fi
            wyjscie=$((wyjscie + 1))
            done;
        if [ "$q" = "t" ] ; then break
        fi
        przeczytane=$((wyjscie + przeczytane))
    done;
    kill -9 $pid 2>/dev/null
    rm $out
    touch $out
done;

rm -rf $katalog

Logs of execution

wytrzeszcz@wytrzeszczPC:~/Dokumenty/PG/so$ ./projekt.sh
+ ./projekt.sh
podaj -h
+ . debug.cfg
++ pliki_in=./
++ pliki_out=./
++ plik_compile=./a.cpp
++ program=a.out
++ flagi=
++ debugpolecenie=debug
+ g++ ./a.cpp -o a.out
+ find ./
+ grep '.in$'
+ sort -u
+ find ./
+ grep '.out$'
+ sort -u
++ cat /tmp/debuger9348/lista.in
+ for in_plik in '`cat $katalog/lista.in`'
+ pid=9365
+ echo 9365
9365
+ cat /tmp/debuger9348/fifo
+ ./a.out -f /tmp/debuger9348/out
++ echo ./1.in
++ sed 's/\// /g'
++ sed 's/.in$//g'
++ awk '{ print $(NF) } '
+ nazwa_in=1
++ cat /tmp/debuger9348/lista.out
++ grep '/1.out$'
+ outtest=./1.out
+ echo ./1.out
./1.out
+ przeczytane=1
+ wyjscie=1
++ cat ./1.in
+ for liniain in '`cat $in_plik`'
++ ps -aux
++ awk '{ print $2 }'
++ grep 9365
+ zycie=9365
+ '[' -n 9365 ']'
+ echo a
+ echo 'linia in: a'
linia in: a
+ cat /tmp/debuger9348/out
a
TEST: 0 a
7
  • do the echo first.
    – mikeserv
    May 11, 2014 at 1:39
  • @mikeserv That shouldn't make a difference. ./a.out will block waiting for input, but since it's started with &, it will do so in the background while the script continues to run.
    – n.st
    May 11, 2014 at 1:41
  • 1
    @wytrzeszcz Please take a look at How to create a Minimal, Complete, and Verifiable example.
    – n.st
    May 11, 2014 at 1:42
  • 1
    @n.st true - but what else is waiting on it in ...?
    – mikeserv
    May 11, 2014 at 1:42
  • @mikeserv You can take a look at the "complite" script, but you'd better know Polish. ;)
    – n.st
    May 11, 2014 at 1:44

1 Answer 1

3

Given the extract, this line blocks, waiting to read data from the pipe:

./a.out <$fifo >$out & pid=$!

Nothing is going to happen until somebody writes to the fifo. This needs to be another process. Typically, you would fork a background reader process, and write to the fifo in the foreground, or vice versa. Here, you're reading, and later your script writes to the pipe: this makes no sense.

In the different complete script that you've posted, the reader runs in the background:

./$program <$fifo >$out &

I haven't read your complete script — you need to work on writing a minimal complete example. I think the issue that you're running into is that end-of-file when reading from a named pipe happens as soon as one writer closes the pipe. But you have many writers:

echo "$debugpolecenie" > $fifo
…
echo "$liniain" >> $fifo

(> and >> make no difference on a pipe, by the way, but you'll want to use >> if you ever switch to a log file.)

You need to open the pipe for writing exactly once. Open it on another file descriptor.

mkfifo $fifo
exec 3>$fifo
…
echo "$debugpolecenie" >&3
…
exec 3>&-  # to close the fifo

or use grouping, where all the code that writes to the pipe is inside the braces:

{
  …
} 3>$fifo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .