Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


PHP exec( ) problems!

Posted on 2003-02-27
Medium Priority
Last Modified: 2006-11-17
Hi all

When I use the exec() call on my Windows 2000 box
in the following form:

exec("command 2>&1",$results);

it works perfectly.  Even if "command" is an incorrect command string $results, as you would expect, will contain the error (ie. Bad command or file name).  But when I use the same structure on Windows 98 only successful "simple" commands work. Nothing is returned at all when there is an error, the $results array is always empty.  This is a problem as I am processing a XML validation using LIBXML and I am interested in finding if there are any errors.    

In the exec call listed above the additional string "2>&1" is supposed to redirect error output to the standard console output.  It doesn't seem that this works in the DOS on 98, is there any way I can return errors to the $results array.

Your help is much appreciated


Question by:kevadooch
LVL 15

Expert Comment

ID: 8032750
all I can say is that I avoid it because in the doc it says "exec() may not work on Windows platform"

Expert Comment

ID: 8033259
The shell processor on W98 is nothing like the one on NT based systems (like WNT, W2000, WXP).  You might ask in the "operating systems" experts area under W98 how to get the errors to go to stdout and then use that in your exec on W98.

Author Comment

ID: 8033338
Unfortunately at this time the only way that one can validate an XML document against a DTD is to use a command line application.  So I'm pretty much reliant on using exec().

A side note is that I have found out that it is pretty much impossible to redirect error output to standard output in Win 98 using the trusty "2>&1" string.  
As the exec() command returns the standard output I'm stumped.  Ahh well, I'll just have to put Windows 2000 or Linux down as a requirement  ...

.. unless anyone knows of a trick of hack to get round this


What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 15

Expert Comment

ID: 8033584
have you tried syntax > c:\textfile.txt and reading that file afterwards ?

Author Comment

ID: 8042728
I have been offered a solution by another expert.
You can use a program called "stderr" to merge the
standrad output streams.  This works a treat!!

Accepted Solution

Computer101 earned 0 total points
ID: 12520267
PAQed with points refunded (50)

EE Admin

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question