Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to open the CD ROM using Perl? If so, how about using CGI as well?

20040618 Edit by castaway: Changed title from 'Opening the CD ROM'

Replies are listed 'Best First'.
Re: Ejecting the CD ROM
by davido (Cardinal) on Jun 14, 2004 at 07:30 UTC
    Searching CPAN for "cdrom" turned this up:

    use SDL::Cdrom; my $cdrom = SDL::Cdrom->new(0); $cdrom->eject();

    If you really want to get crazy, I suppose you could write a CGI script that allows people to eject your CDRom via a webpage. ...don't know why you would want to do that though. As for you being able to eject the cdrom's of people visiting your website, thankfully that can't be done with CGI via plain Perl. You may want to visit the Visual Basic folks for that. ;) (just kidding).

    Anyway, have a look at SDL::Cdrom.


    Dave

Re: Ejecting the CD ROM
by amw1 (Friar) on Jun 14, 2004 at 14:31 UTC
    A different way to do it (without modules, only works on *nix boxes)
    qx|/usr/bin/eject /dev/cdrom|;
    You have to check the path of both your cdrom device and your eject binary. Not terribly portable but you may not care.
Re: Ejecting the CD ROM
by Mr. Muskrat (Canon) on Jun 15, 2004 at 04:11 UTC

    When Aldo "dada" Calpini uploaded Win32::API to CPAN he included some samples. One of those samples is ejectcd.pl and it looks like this:

    #perl -w use strict; use Win32::API; my $mciSendString = new Win32::API( "winmm", "mciSendString", ['P', 'P', 'N', 'N'], 'N' ) or die "Can't import the mciSendString API:\n$!"; doMM("close cdaudio"); doMM("open cdaudio shareable"); doMM("set cdaudio door open"); doMM("close cdaudio"); sub doMM { my($cmd) = @_; my $ret = "\0" x 1025; my $rc = $mciSendString->Call($cmd, $ret, 1024, 0); if($rc == 0) { $ret =~ s/\0*$//; return $ret; } else { return "error '$cmd': $rc"; } }