简体   繁体   中英

Executing bash script from php not working on Windows

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 ?

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;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM