Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a CD in the drive? (LINUX) 1

Status
Not open for further replies.

fopetesl

Programmer
Dec 14, 2002
6
GB
Hi all. Newbie here to PHP (V4.3.3).
I run a Bash script to check if CD has been inserted into drive:

Code:
$restoreit = system(`/var/[URL unfurl="true"]www/html/cd2db1`,[/URL] $retval);
echo "&result=$restoreit";
break;

and read the "echo" result in Flash.
I can see/read "&result=" but nothing else, ($restoreit always a NULL?), WHATEVER I try ..e.g. passthru(); ???_exec();...

If I run "cd2db1" from a command line it works fine and returns the line:
cp: cannot stat "/mnt/cdrom/db.sql" : No medium found

What I need to see/read is the "No medium found" when no CD present ..using stristr() (?,etc..) eventually.

I have also tried ...

Code:
$restoreit = system('cp /mnt/cdrom/db.sql /var/[URL unfurl="true"]www/html/ALMETER-RESTORE',[/URL] $retval);
echo "&result=$restoreit";
break;

.. and that doesn't work either. All I see is "&result="

Are we looking at a permission thing here? Or what?

Peter
 
Hi Eric(?) ty for your input:
'ticks' are 'forward' ticks and I am not attempting to run/execute the output. Flash MX2004 'reads' the "echo..." line. Flash just never gets a result from PHP $restoreit unless I specifically write something to it myself. e.g.
Code:
$restoreit = "Test Result";
echo "&result=$restoreit";
break;
.. this works OK and Flash can see &result=Test Result, but when I code...
Code:
$restoreit = "Test Result";
$restoreit = system('cp /mnt/cdrom/db.sql var/[URL unfurl="true"]www/html/ALMETER-RESTORE',[/URL] $retval);
echo "&result=$restoreit";
break;
.. Flash only reads &result=, i.e. $restoreit gets nuked.

Peter
 
From the manual:

system() is just like the C version of the function in that it executes the given command and outputs the result. If a variable is provided as the second argument, then the return status code of the executed command will be written to this variable.

If you want the result in the variable you'll either need to use backticks or popen and read it back.

Code:
$restoreit = `your command`;

But the other issue is, cp doesn't make any output.
 
Problem is when I do use backticks I get the error message:
Code:
Warning: system(): cannot execute a blank command in ... line 760
759  $restoreit = "Test Result";
760  $restoreit = system('cp /mnt/cdrom/db.sql var/[URL unfurl="true"]www/html/ALMETER-RESTORE',[/URL] $retval);
761  echo "&result=$restoreit";

Secondly, cp doesn't make any output? How then do I get to see the message I would get from a cp console command as above? - in variable $restoreit.

ty again
 
You must have a different cp than I do, mine doesn't output anything.

Code:
s2(~)$ cp junk junk2
s2(~)$

But as for the backticks, don't use:
$restoreid = ( `cp /mnt/cdrom/db.sql var/ $retval);

use:
$restoreit = `your command`;
...like I said.

*BUT* cp doesn't normally create any output.

See if you have an alias for cp in your environment.

Try this:
$restoreit = `cp -v /mnt/cdrom/db.sql var/
 
Eric TY.
OK. Humour me. Try this:
Make sure no CD in drive.
Code:
s2(~)$ cp /mnt/cdrom/* .
and see what comes back.

Meanwhile I'll try your other suggestions.
 
OK. I tried:
Code:
$restoreit = `cp -v /mnt/cdrom/db.sql var/[URL unfurl="true"]www/html/ALMETER-RESTORE`;[/URL]

Sorry. Still get &result=

However. I can get a result from:
Code:
    `sudo /usr/bin/eject`;
    `sudo /bin/sleep 20`;
    $handle = opendir("/mnt/cdrom/");
    echo "&result=";
    if( false === ($file = readdir($handle))) {
      echo "No Disk in drive";
    }
   else
    {
      while( $file != "Mandrake" && (false !== ($file = readdir($handle))) );
      if( $file == "Mandrake")
       echo "**SUCCESS**";
      else
       echo "FILE NOT FOUND!";
    }
	 break;

It's a work around but I still cannot read result from Bash scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top