473,320 Members | 2,162 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,320 software developers and data experts.

exec() works only sometimes

Hello!

I run PHP 4.3 as an Apache module. I use Apache 1.3 as a service under
WinXP. And I've got a strange problem with exec():

The following commands are executed correctly:
c:\windows\system32\cmd.exe /?
c:\apache\apache.exe -w -n "Apache" -k restart

The following commands are not executed (empty output array, return code =
1):
c:\Apache\Apache.exe -h
c:\windows\system32\cmd.exe /C c:\apache\apache.exe -h

It works with the console, however. So why not with PHP?

Can anyone help me?
Thomas
Jul 17 '05 #1
6 2012
On Thu, 23 Sep 2004 16:41:39 +0200, "Thomas Mlynarczyk"
<bl*************@hotmail.com> wrote:
I run PHP 4.3 as an Apache module. I use Apache 1.3 as a service under
WinXP. And I've got a strange problem with exec():

The following commands are executed correctly:
c:\windows\system32\cmd.exe /?
c:\apache\apache.exe -w -n "Apache" -k restart

The following commands are not executed (empty output array, return code =
1):
c:\Apache\Apache.exe -h
c:\windows\system32\cmd.exe /C c:\apache\apache.exe -h

It works with the console, however. So why not with PHP?


This is in fact consistent - the commands ARE being run. The convention for
'usage' commands is to output the usage information on standard error and NOT
standard output, and to exit with a non-zero (failure) error code.

D:\Apache2\bin>apache.exe -h
Usage: apache.exe [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-w] [-k start|restart|stop|shutdown]
[-k install|config|uninstall] [-n service_name]
[-v] [-V] [-h] [-l] [-L] [-t] [-S]
Options:
-D name : define a name for use in <IfDefine name> directives
[ ... snip ... ]
-t : run syntax check for config files

D:\Apache2\bin>echo %ERRORLEVEL%
1

There's your '1' return code.

D:\Apache2\bin>apache.exe -h 2>NUL

D:\Apache2\bin>

Redirecting standard error shows that there's nothing sent to standard output.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Also sprach Andy Hassall:

[some exec() commands work, others not]
This is in fact consistent - the commands ARE being run. The
convention for 'usage' commands is to output the usage information on
standard error and NOT standard output, and to exit with a non-zero
(failure) error code.
Thanks for shedding some light on this mystery.
D:\Apache2\bin>apache.exe -h 2>NUL


What does the "2" in the above mean?

Jul 17 '05 #3
Thomas Mlynarczyk <bl*************@hotmail.com> wrote:
Also sprach Andy Hassall:

[some exec() commands work, others not]
This is in fact consistent - the commands ARE being run. The
convention for 'usage' commands is to output the usage information on
standard error and NOT standard output, and to exit with a non-zero
(failure) error code.


Thanks for shedding some light on this mystery.
D:\Apache2\bin>apache.exe -h 2>NUL


What does the "2" in the above mean?


It's the standard stream constant iirc:
0 - STDIN
1 - STDOUT
2 - STDERR
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #4
Also sprach Simon Stienen:
D:\Apache2\bin>apache.exe -h 2>NUL


What does the "2" in the above mean?


It's the standard stream constant iirc:
0 - STDIN
1 - STDOUT
2 - STDERR


I tried it appending 2>&1 to the command (had not tried that before as I
thought this was *nix only) and bingo! It works! Only thing I wonder: If
Apache is supposed to return an error code of 0 if all is OK, how can I find
out about it?

Thanks again to all of you!
Thomas
Jul 17 '05 #5
Thomas Mlynarczyk <bl*************@hotmail.com> wrote:
Also sprach Simon Stienen:
D:\Apache2\bin>apache.exe -h 2>NUL

What does the "2" in the above mean?


It's the standard stream constant iirc:
0 - STDIN
1 - STDOUT
2 - STDERR


I tried it appending 2>&1 to the command (had not tried that before as I
thought this was *nix only) and bingo! It works! Only thing I wonder: If
Apache is supposed to return an error code of 0 if all is OK, how can I find
out about it?

Thanks again to all of you!
Thomas


http://de3.php.net/function.exec states:
| string exec ( string command [, array &output [, int &return_var]])
^^^^^^^^^^^^^^^
Saying in the function description:
| If the return_var argument is present along with the output argument,
| then the return status of the executed command will be written to this
| variable.

HTH
Simon
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #6
Also sprach Simon Stienen:
http://de3.php.net/function.exec states:
string exec ( string command [, array &output [, int &return_var]])

^^^^^^^^^^^^^^^
Saying in the function description:
If the return_var argument is present along with the output argument,
then the return status of the executed command will be written to
this variable.


Well, I use the exec() with both $output array and $return variable. And the
latter contains 1, even though the command is supposed to have been
successful.
Jul 17 '05 #7

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

Similar topics

4
by: Andrew Crowe | last post by:
Hi guys, I'm using ImageMagick to do scaling / filtering to uploaded images by calling the following: exec("cmd.exe /c convert.exe -filters in.jpg out.jpg"); This works flawlessly on our...
2
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each...
1
by: Hal Vaughan | last post by:
I've been using Runtime.exec() like this: Runtime rt = Runtime.getRuntime(); try {Process p = rt.exec("MyCommand.bat");} catch (Exception e) {do stuff} When I start my Java classes, I start...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
5
by: TPJ | last post by:
I have the following code: ----------------------------------- def f(): def g(): a = 'a' # marked line 1 exec 'a = "b"' in globals(), locals() print "g: a =", a
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
26
by: warth33 | last post by:
Hello I have a php site. Some page needs to call an external program. The programs are home made c# applications. It uses to work without problem. For a while. Maybe it work for some hour....
0
by: Gabriel Genellina | last post by:
En Sat, 12 Jul 2008 16:15:36 -0300, Akathorn Greyhat <akathorn@gmail.com> escribi�: Welcome! You have to pass in the namespace of the desired module - instead of globals. I'd use an...
0
by: Stef Mientki | last post by:
Terry Reedy wrote: The locals of the code block where the instance of this class is created. No I think it's indeed handled as function call. I now that, because the globals (and sometimes ??? the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.