0

I have executed this script under xampp ( ubuntu ) it works fine. but when i tried to execute it under windows it gives me no error but also no output.

<? $command='ls -l'; $output = shell_exec($command); echo $output; ?>

PHP do not run in save mode. what is the problem ? is it depending on the OS ?

1
  • In short, yes. There are Bourne Shell implementations available for Windows (so that you'll be able to run bash scripts). unxutils.sourceforge.net Commented Aug 10, 2012 at 15:35

1 Answer 1

3

This is because ls is unix based command and is not available on Windows

Not showing errors is because shell_exec only outputs STDOUT and not STDERR, if you want to be able to view error you can run your command like this:

$output = shell_exec("{$command} 2>&1");

which will show an error stating that ls was not found or something similar

in windows instead of ls you can run dir

this might help:

<?
    $command=substr(PHP_OS, 0, 3)=='WIN'?'dir':'ls -l';
    $output = shell_exec("{$command} 2>&1");
    echo $output;
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.