Detecting if DVD in drive

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

Code:
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

Code:
readcd -scanbus | grep 'CD-ROM'

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

Any ideas?
 
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
status: 0x2 (CHECK CONDITION)
Sense Bytes: 70 00 05 00 00 00 00 0A 00 00 00 00 25 00 00 00 00 00
Sense Key: 0x5 Illegal Request, Segment 0
Sense Code: 0x25 Qual 0x00 (logical unit not supported) Fru 0x0
Sense flags: Blk 0 (not valid)
cmd finished after 0.002s timeout 40s
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.
 
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.
 
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."
 
Back
Top