473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP script can't write to stdout nor to error log

<?php

class FileRemoval {

var $fileNameArray, $isRemoved, $errorMsg = '';

function FileRemoval() { // CONSTRUCTOR
$this->fileNameArray = array();
$this->isRemoved = 0;
}
// --* GETTER/SETTER METHODS *--
function getErrorMsg() { // STRING METHOD
return $this->errorMsg;
}

function getIsRemoved() { // BOOLEAN METHOD
return $this->isRemoved;
}

function setFileNameArray() { // VOID METHOD
global $argv;
$junk = array_shift($argv); // LOB OFF FIRST ARRAY ELEMENT YOU
DON'T NEED THE SCRIPT NAME
$this->fileNameArray = $argv;
}

function remove() { // VOID METHOD
$this->setFileNameArray();
if (sizeof($this->fileNameArray) == 0) $this->errorMsg = "No files
provided for removal\n";
if (!$this->getErrorMsg()) {
foreach ($this->fileNameArray as $val) {
if (!file_exists($val) || strlen($val) == 0) {
$this->errorMsg = "File: '$val' does not exist ";
break;
}
@unlink($val);
}
if (!$this->getErrorMsg()) $this->isRemoved = 1;
}
}

function writeErr() { // VOID METHOD
if ($this->getErrorMsg()) {
$myErr = '[' . date("d/M/Y:H:i:s"). '] ' . $this->errorMsg;
$fileID = @fopen('./cmds.err', 'a') or die("Could not find error
log");
fputs($fileID, $myErr); fflush($fileID); fclose($fileID);
$fileID = @fopen('php://stdout', 'a') or die("Could not open
STDOUT");
fputs($fileID, $myErr); fflush($fileID); fclose($fileID);
}
}

function writeFileNameArrayMsg() { // VOID METHOD
if (!$this->fileNameArray || @sizeof($this->fileNameArray) == 0) {
$this->errorMsg = "There are no files to remove\n";
$fileID = @fopen('php://stdout', 'a') or die("Could not open
STDOUT");
fputs($fileID, $this->getErrorMsg()); fflush($fileID);
fclose($fileID);
} else {
foreach ($this->fileNameArray as $val) {
$msg .= "\nFile: '$val' has been deleted";
if (array_search($val, $this->fileNameArray) ===
sizeof($this->fileNameArray) - 1) $msg .= "\n";
}
$fileID = @fopen('php://stdout', 'a') or die("Could not open
STDOUT");
fputs($fileID, $msg); fflush($fileID); fclose($fileID);
}
}

}

// ----- END OF CLASS
-----------------------------------------------------
// MAIN SCRIPT - INSTANTIATE A FileRemoval CLASS OBJECT INSTANCE AND
RUN THE remove() METHOD

$hasPrintedErr = false;
$fileRemoval =& new FileRemoval();
$fileRemoval->remove();
if (!$fileRemoval->getIsRemoved()) {
$fileRemoval->writeErr();
$hasPrintedErr = true;
}
$fileRemoval->writeFileNameArrayMsg();
if ($fileRemoval->getErrorMsg() && !$hasPrintedErr)
$fileRemoval->writeErr();
$fileRemoval = null;

?>

I have done everything I can think of to get messages to print using
either writeErr() method or writeFileNameArrayMsg() method, however,
nothing appears in stdout nor in cmds.err no matter what I do. The
PHP script is a command-line PHP script called by the following:

php -q /../fileremoval.php $fileList

And I can verify that the files are being removed by the remove()
method every time, that works. But no messages ever appear either in
stdout nor in the error log indicating anything, no matter what I do,
nothing appears. However, if I call the file from the command line
prompt:

php -q /./fileremoval.php[list of existing files]

It works just fine and produces messages. But I am calling this
script from 2 other scripts:

cmds.sh -a --transferfiles --delete -d /me/dummy

Which calls

tclsh /../transfer/archive.tcl"

which it calls

eval "exec php -q /../fileremoval.php $fileList

I traced all of my coding to indicate that everything functions
properly, except in the case of the PHP script simply never producing
any output anywhere unless I call it directly, once again, from the
command line prompt.

I could honestly use some extra pairs of eyes to view my PHP code and
tell me if the code is wrong, or if there is some way that stdout
and/or stderr >> /cmds.err has been somehow either redirected or
overwritten by something else. I speak very little "techie" so that's
the best I can explain it to anyone.

Help!

Thanx
Phil
Jul 17 '05 #1
0 4645

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
<?php class FileRemoval { var $fileNameArray, $isRemoved, $errorMsg = ''; function FileRemoval() { $this->fileNameArray = array(); $this->isRemoved = 0; }
7
by: black | last post by:
hi all~ in my .py file there are a few print to trace out some message and i wonder if we can save it into a specified file when that script get running. if so, i may just check that file to c...
17
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
2
by: André | last post by:
Short description: Using a wxPython based app, I would like to take a python script in an editor window, invoke the python interpreter and use another window as stdin/stdout/stderr. Based on...
13
by: wattersmt | last post by:
Hello, I am trying to write a python cgi that calls a script over ssh, the problem is the script takes a very long time to execute so Apache makes the CGI time out and I never see any output. ...
2
by: Gerard Flanagan | last post by:
Hello, I have a third party shell script which updates multiple environment values, and I want to investigate (and ultimately capture to python) the environment state after the script has run....
4
by: dbee | last post by:
Right. I've got a really, really annoying/difficult/time consuming problem with my development environment. I'm using django to build a web app with paypal integration. My server is hosted...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: Gabriel Genellina | last post by:
En Mon, 20 Oct 2008 06:15:34 -0200, Gatis <gatisl@inbox.lvescribió: Use the subprocess module to invoke the external program; see http://docs.python.org/library/subprocess.html specially the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.