0 votes
by Bill Codington (190 points)
For instance this command:

z" qiv -X 1 /home/pi/graphics/2.JPG &" >system

will return a result code while the image is displayed, but not the process #, Like the Terminal window:

pi@raspberrypi:~ $ qiv -X 1 /home/pi/graphics/1.JPG &
[1] 2933
I would like to direct "q" to the window or Kill the process when I want to display another image.

I have found at least 3 image display apps that work but I need to be able to close them.

Thanks

2 Answers

+1 vote
by Bart Nelson (480 points)

The

`>system` 

word does not give you enough feedback.

See the word:

`>pshell` instead.

You will need to modify your command to capture the special environment variable '$!' (PID of last process). Don't forget to check for return errors on both STDERR and also from the shell.

e.g.

`yes >/dev/null & PID=$! && sleep 5 && kill $PID`
+1 vote
by Daniel Lee (630 points)

Here's one way to save your image viewer's process id (PID) and close it later:

z" qiv Doc/bertie.jpg & echo $! > qiv.pid" >system

As mentioned in the previous answer, the $! environment variable gives the PID of the most recent process.  The PID is captured to the file qiv.pid.

Then use the command pkill to kill the process with the captured PID:

z" pkill -F qiv.pid" >system

...