How to get status code of program piped to linux dialog command

2

I am trying to use Linux dialog to prepare simple installer for Ubuntu. The actual command is:

  dpkg -i package.deb 2>&1 | dialog --programbox "Installing..." 10 100

I want dialog to display any output produced by the dpkg command whether it is normal output or error message, so I redirect stderr to stdout. This works.

The problem is that I need status code of the dpkg command after both commands ended. Just to know if the dpkg did its job or not. Unfortunately, after these commands ended I can only get status code of the dialog command...

Anyone knows how to obtain status code of the dpkg command from above example?

WRz

Posted 2014-10-22T08:14:23.227

Reputation: 123

Answers

2

What you search is the pipestatus:

dpkg -i ... | dialog ...
echo ${PIPESTATUS[0]} # this contains the exit code of the dpkg command.

See that example:

$ false | true | false | true
$ echo ${PIPESTATUS[@]}
1 0 1 0

chaos

Posted 2014-10-22T08:14:23.227

Reputation: 3 704

This is exactly what I was looking for! Thank you! – WRz – 2014-10-22T12:42:30.200