Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从PHP执行命令?_Php - Fatal编程技术网

如何从PHP执行命令?

如何从PHP执行命令?,php,Php,我的意思是,如果有人点击一个按钮,它就会运行一个命令并创建一个文件。我想在Windows服务器上使用它。要在php中执行命令,可以使用 exec-执行外部程序 系统-执行外部程序并显示输出 passthru-执行外部程序并显示原始输出 根据返回数据的方式不同,工作方式也不同。您可以使用exec关键字在linux或windows上执行命令,但 如果在Windows server上使用,请将php.exe的完整路径和script.php的 举例来说 exec("d:/path/php/execu

我的意思是,如果有人点击一个按钮,它就会运行一个命令并创建一个文件。我想在Windows服务器上使用它。

要在php中执行命令,可以使用

exec-执行外部程序

系统-执行外部程序并显示输出

passthru-执行外部程序并显示原始输出


根据返回数据的方式不同,工作方式也不同。

您可以使用
exec
关键字在linux或windows上执行命令,但 如果在Windows server上使用,请将php.exe的完整路径script.php的 举例来说

exec("d:/path/php/executable/php.exe d:/wamp/www/program/defender/tester.php", $myout);

print_r($myout);

你可以使用,你可以使用,例如


首先必须在客户端上创建一个按钮或表单,然后必须实现逻辑,以便在按下按钮后将请求发送到服务器

然后在服务器端,您必须执行代码:

e、 g


这个shell\u exec是在windows服务器上工作还是只在linux上工作?它也在windows上工作
$command = 'ping -c 3 stackoverflow.com';

//shell_exec()
shell_exec($command);

//system()
system($command);

//``
`$command`;

//exec()
exec($command);

//proc_open()
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);
$process = proc_open($command, $descriptorspec, $pipes);

//passthru()
passthru($command);
<?php
  echo shell_exec('cmd /?h > randomFile.txt');