# Detecting if DVD in drive



## roddierod (May 21, 2009)

I'm working on a Python script and I want to test to see if a DVD is in the drive.

I was planning on subprocess.Popen and just calling


```
readcd dev=2,0,0 | grep 'Sense Code:'
```

but it seems that the grep isn't respected as the full ouput of the readcd command is returned.

But


```
readcd -scanbus | grep 'CD-ROM'
```

returns what I expect, just the line with the CD-ROM info.

Any ideas?


----------



## fronclynne (May 22, 2009)

*Maybe bash would handle your MOM better!  Zing!*

Is readcd's output going to stderr instead of stdout?

readcd(1) (whoops, it's part of ports, not base) saith:





> A typical error message for a SCSI command looks like:
> 
> readcd: I/O error. test unit ready: scsi sendcmd: no error
> CDB:  00 20 00 00 00 00
> ...


So maybe bash would handle this sort of nonsense better?  (I don't know, I am slightly crazy and extremely ignorant)

Edit:
Addendum:
AUTHOR
       Joerg Schilling

I should have known, from all of the crabbing about linux's scsi drivers in the man page.


----------



## roddierod (May 22, 2009)

Ah Sir! I was only checking on stdout not stderr it never occurred to me that since there is no DVD in the drive it was an error...duh!

By using subprocess in python I'am issuing bash commands. I'm using python becaus of all the other things this script is intended to do. 

It's a custom backup script that will burn the data to DVD when the backup archives are at a certain size.


----------



## fronclynne (May 23, 2009)

Ah, I was just thinking of the redirection stderr & stdout, but I suppose snake-named things do their own thing.

But, yes, unexpectedly using stderr like that fits my mental image of Shilling to a "T": "Though I speak with the tongues of men and of angels, and have not charity, I am become as sounding brass, or a tinkling cymbal."


----------

