简体   繁体   English

从php执行bash脚本在Windows上不起作用

[英]Executing bash script from php not working on Windows

I have executed this script under xampp ( ubuntu ) it works fine. 我已经在xampp(ubuntu)下执行了该脚本,效果很好。 but when i tried to execute it under windows it gives me no error but also no output. 但是当我尝试在Windows下执行它时,没有错误但也没有输出。

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

PHP do not run in save mode. PHP不在保存模式下运行。 what is the problem ? 问题是什么 ? is it depending on the OS ? 是否取决于操作系统?

This is because ls is unix based command and is not available on Windows 这是因为ls是基于unix的命令,在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: 未显示错误是因为shell_exec仅输出STDOUT而不输出STDERR,如果您希望能够查看错误,则可以这样运行命令:

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

which will show an error stating that ls was not found or something similar 这将显示一个错误,指出找不到ls或类似的东西

in windows instead of ls you can run dir 在Windows而不是ls中,您可以运行dir

this might help: 这可能会有所帮助:

<?
    $command=substr(PHP_OS, 0, 3)=='WIN'?'dir':'ls -l';
    $output = shell_exec("{$command} 2>&1");
    echo $output;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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