# How to check for an error if executing a shell command e.g

**URL:** <https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944>\
**Category:** Ruby\
**Created:** [August 24, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944 "2007-08-24T20:05:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 24, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944/1 "2007-08-24T20:05:40Z")

</div>

Hi,  
I’m writing a little script to install some drivers but I wanna react in  
this script if any step fails. So e.g. I’m doing this:  
system(‘dpkg -i xorg-driver-fglrx fglrx-kernel-source’)  
How can I check if this was succesful or if there was any error?

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 24, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944/2 "2007-08-24T20:12:41Z")

</div>

Alle venerdì 24 agosto 2007, kazaam ha scritto:

> Hi,  
> I’m writing a little script to install some drivers but I wanna react in  
> this script if any step fails. So e.g. I’m doing this: system(‘dpkg -i  
> xorg-driver-fglrx fglrx-kernel-source’)  
> How can I check if this was succesful or if there was any error?

I think you should check the return value of system. It will return true  
if  
the command was run successfully and false otherwise.

Stefano

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 24, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944/3 "2007-08-24T20:25:44Z")

</div>

lol thanks this really works 😃

On Sat, 25 Aug 2007 03:11:20 +0900

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 24, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944/4 "2007-08-24T20:15:43Z")

</div>

kazaam wrote:

> system(‘dpkg -i xorg-driver-fglrx fglrx-kernel-source’)  
> How can I check if this was succesful or if there was any error?

system returns true or false depending on whether or not the command  
exited  
successfully. You can also look at the exit status via the global var $?  
HTH

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 24, 2007, 10:11pm UTC](https://www.ruby-forum.com/t/how-to-check-for-an-error-if-executing-a-shell-command-e-g/112944/5 "2007-08-24T22:11:10Z")

</div>

On Fri, 2007-08-24 at 20:07 +0200, Sebastian H. wrote:

> kazaam wrote:
> 
> > system(‘dpkg -i xorg-driver-fglrx fglrx-kernel-source’)  
> > How can I check if this was succesful or if there was any error?
> 
> system returns true or false depending on whether or not the command exited  
> successfully. You can also look at the exit status via the global var $?  
> HTH

popen4
