Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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脚本来执行shell命令,将文本写入另一个php文件?_Php_Linux_Shell_Execute_Shell Exec - Fatal编程技术网

如何创建一个php脚本来执行shell命令,将文本写入另一个php文件?

如何创建一个php脚本来执行shell命令,将文本写入另一个php文件?,php,linux,shell,execute,shell-exec,Php,Linux,Shell,Execute,Shell Exec,如何创建一个php脚本来执行shell命令,将文本写入另一个php文件?而且没有任何sudo问题。到目前为止,我有这个 <?php include("inc/config.php"); $command = "sed -i '$ a\this is line 2 without redirection' admin.php"; $command1 = "cat admin.php"; $output = shell_exec($command); $output1 = shell_exec

如何创建一个php脚本来执行shell命令,将文本写入另一个php文件?而且没有任何sudo问题。到目前为止,我有这个

<?php
include("inc/config.php");
$command = "sed -i '$ a\this is line 2 without redirection' admin.php";
$command1 = "cat admin.php";
$output = shell_exec($command);
$output1 = shell_exec($command1);
echo "<pre>$output</pre>";
echo "<pre>$output1</pre>";
?>

您的脚本需要在有权限执行所有需要执行的操作的帐户下运行。就这么简单。

您的脚本需要在一个帐户下运行,该帐户有权执行您需要执行的所有操作。就这么简单。

我不知道你的意思,但是shell_exec(“bash命令要使用”);我只是想知道,为什么要使用shell命令,因为在大多数情况下,
fopen()
-
fwrite
-
fclose
?我不知道你的意思,但是shell_exec(“bash commands to want to use”);我只是想知道,为什么要使用shell命令,因为在大多数情况下,
fopen()
-
fwrite
-
fclose
?同意,还要确保
shell\u exec
不是php.ini文件中指定的。与一些共享主机提供商达成一致。此外,还要确保
shell_exec
不是php.ini文件中指定的。对于一些共享主机提供商来说,这是一个很好的选择。