Interactive shell through a pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interactive shell through a pipe
# 1  
Old 02-06-2010
Interactive shell through a pipe

I'm new to working with pipes, so I don't know whether the following is expected behaviour or a bug on the part of an application.

Since Version 0.47, Inkscape provides a non-GUI interactive shell mode of operation. I am trying to time the program's performance in converting SVG files to PNG images and compare this to other apps. Inkscape expects a line of optional arguments and a file name to be delivered to its command prompt. (see the bottom part of Chapter 24. Using the Command Line for an example how it works) I am using a named pipe for delivering these lines. My benchmarking scripts are these:

svgbench.sh
Code:
#!/bin/bash

export BASEDIR=~/PNGs
export SVGDIR=$BASEDIR/svg
export SCRDIR=$BASEDIR/scripts
export WIDTH=600
 
mkfifo in.fifo
mkfifo out.fifo
inkscape --shell <in.fifo >>out.fifo 2>>$SCRDIR/error &
                                           # start Inkscape in shell mode
                                           # and link stdin and stdout to named pipes

i=1
while [ $i -le 5 ]                         # multiple runs through all tested apps
do
    echo "Inkscape-shell" >>$SCRDIR/error  # time Inkscape
    /usr/bin/time --format 'Inkscape-shell     %e\t%U\t%S' -a --output=$SCRDIR/times $SCRDIR/inkscape-shell.sh
    echo "Rsvg" >>$SCRDIR/error            # time Gnome's librsvg
    /usr/bin/time --format 'rsvg               %e\t%U\t%S' -a --output=$SCRDIR/times $SCRDIR/rsvg.sh
    echo "" >> $SCRDIR/times
    i=`expr $i + 1`
done

echo "quit" >> in.fifo                     # quit Inkscape
rm in.fifo
rm out.fifo

inkscape-shell.sh
Code:
#!/bin/bash

for TESTFILE in `ls $SVGDIR`   # get a list of test files
do
    echo $TESTFILE " ">>$SCRDIR/error
    OUTFILE=$(basename $TESTFILE .svg).png
    TESTFILE=$SVGDIR/$TESTFILE
    echo "-w $WIDTH -y 0.0 -e $BASEDIR/inkscape1/$OUTFILE $TESTFILE"
                               # command line for Inkscape
    read -sd ">" < out.fifo    # wait until input prompt gets thrown back
done >> in.fifo
echo >>$SCRDIR/error

As you can see, the pipe Inkscape gets its commands from is accessed consecutively from different processes (one for every test loop, and the 'quit' command), and there are times when the pipe in.fifo is not connected to any file descriptor. Whenever this happens, Inkscape quits, even if no explicit quit command is given.

I have tracked this behaviour back to this: man pipe(7) states "If all file descriptors referring to the write end of a pipe have been closed, then an attempt to read from the pipe will see end-of-file (read will return 0)." Looking closely at the accordant source code of Inkscape, I think what happens is that
  • stdin is read continuously in a loop
  • fgets() in line 01059 means that an EOF will cause the loop and consequently the programm to quit.
Now my question: is this the expected behaviour of an interactive shell program, or should it be perceived as a bug?

And if it is to be expected, how could I achieve a timed execution of inkscape-shell.sh without forking to a new process? Are there other ways to feed lines to an interactive shell?
# 2  
Old 02-07-2010
Hi.

Responding only to your question:
Quote:
Are there other ways to feed lines to an interactive shell?
Many find a solution in the non-trivial system expect:
Code:
INTRODUCTION
       Expect  is a program that "talks" to other interactive programs accord-
       ing to a script.  Following  the  script,  Expect  knows  what  can  be
       expected  from  a  program and what the correct response should be.

-- excerpt from man expect

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Interactive UNIX shell query

Hi guys, I've create 3 shells concerning my work, which named as 1.sh, 2.sh and 3.sh. However, how can I make an interactive query for these shells just like the old (fdisk) in windows9x. I want to make an interface tells the user just like this: Press 1 to execute "1.sh" Press 2 to... (5 Replies)
Discussion started by: leo_ultra_leo
5 Replies

2. Shell Programming and Scripting

Shell script using an interactive command

Hello experts, I have a to write script for monitoring, the script would use a command and I plan to write the script as follows while true do command -arg sleep 2 clear done The output would be set up on a screen for monitoring. However the issue is that the command used in... (2 Replies)
Discussion started by: maverick_here
2 Replies

3. UNIX for Dummies Questions & Answers

What is login and interactive shell?

Hi Guys, Excuse if am asking silly Que ... :rolleyes: Please explain me whats difference between login and interactive shell in Linux .. Have googled but still in doubt .. :confused: --Shirish Shukla (4 Replies)
Discussion started by: Shirishlnx
4 Replies

4. Shell Programming and Scripting

Interactive shell - Give answers to shell

Hi, I have a script that calles some other scripts. Those scripts are expecting some inputs. Right no I am typing manually. But now the number of questions from other scripts are too much and I want to give asnwers autimatically. example. Other scripts gives me 2 options 1) joom... (2 Replies)
Discussion started by: microsim
2 Replies

5. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

6. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

7. Shell Programming and Scripting

feeding interactive shell commands

Hi, like if i want to authenticate and i 100% know the password and username i can run a script with su - username and then feed in the password through file pass.txt script.sh < pass.txt but if i don't know in which order the script is going to prompt for the input is there a way i... (4 Replies)
Discussion started by: ltoso
4 Replies

8. Shell Programming and Scripting

Schedule an interactive shell script

Hi, I need to schedule a shell script which executes another shell script along with a series of other commands. When the inner shell script is executed it prompts for a password..... This inner shell cannot be changed How can I do this???? Regards, Chaitrali. (4 Replies)
Discussion started by: Chaitrali
4 Replies

9. Shell Programming and Scripting

Korn shell interactive script

Hi, How can I prompt a user for two input and pass the input to variables in the script. I have the following script but it is not working: +++++++++Begin+++++++++++ #!/bin/sh database_c=$1 output_f=$2 echo "Your db is $1\nOutput is $2" +++++++++End+++++++++++ Thanks, Leonard (3 Replies)
Discussion started by: leonard905
3 Replies

10. Programming

need help in implementing simple interactive shell in C

hello all, i hv attached herewith my program to implement a simple interactive shell in C. no matter hw hard I try, I keep getting some errors. i need help - urgently !! proj1test7.c: In function `parseCommand': proj1test7.c:102: warning: assignment makes pointer from integer without a cast... (2 Replies)
Discussion started by: nix1209
2 Replies
Login or Register to Ask a Question