【PHP命令行工具shell_exec,exec,passthru,system详细使用介绍_php技巧】教程文章相关的互联网学习教程文章

PHP命令shell_exec()无法用于我的自定义Java应用程序5【代码】

我已经制作了一个自定义Java程序来输出许可证,并尝试在php中运行它.$deviceid="12345"; $command_app = 'java -jar /home/myname/secure/mycommand.jar '; $privateKey = 'QEFAASCAmEwggJdAgE'; $command_app_args = "\"$privateKey\" deviceid=$deviceid"; $command=$command_app.$command_app_args; $license = shell_exec($command);问题是$license每次都是空的,我尝试使用以下命令打印$commandecho $command;然后直接在linux终...

php-通过shell_exec使用utf-8文本输入来调用程序【代码】

资格:hunspell和php5. 来自bash的测试代码:user@host ~/ $echo 'sagadījās' | hunspell -d lv_LV,en_US Hunspell 1.2.14 + sagadīties-正常工作. 测试代码(test.php):$encoding = "lv_LV.utf-8";setlocale(LC_CTYPE, $encoding); // test putenv('LANG='.$encoding); // and another test$raw_response = shell_exec("LANG=$encoding; echo 'sagadījās' | hunspell -d lv_LV,en_US");echo $raw_response;回报Hunspell 1.2....

在PHP中,shell_exec和proc_open有其他替代方法吗?

看来我无法在共享服务器上使用shell_exec或proc_open. 尝试使用时收到的消息是:Warning: shell_exec() has been disabled for security reasons in /home/georgee/public_html/admin/email.php on line 4这些功能还有其他选择吗?解决方法:我假设您想将其用于异步处理,例如在单独的进程中发送电子邮件(因此email.php中的错误).如果是这样,请检查是否启用了cURL.您可以通过HTTP请求触发脚本,而无需等待响应. 进一步阅读: > Asynch...

PHP shell_exec,执行-rwxrwxrwx shell脚本的权限被拒绝【代码】

我目前在一个运行Apache网络服务器的远程CentOS 5.6系统上运行ssh.我需要使用poppler pdftohtml二进制文件,遗憾的是,该二进制文件当前未安装在该计算机上.所以我下载了poppler包并在我的用户文件夹下构建它.因为我不是系统管理员,所以我没有make install我的所有编译文件都在/users/myfolder/poppler-0.18.2/我需要通过php shell_exec()执行的文件是/users/myfolder/poppler-0.18.2/utils/pdftohtml如果我通过ssh bash执行它,我会得...

使用shell_exec从PHP中调用Python【代码】

我的默认Web应用程序基于PHP.但是,为了方便起见,我构建了一个python脚本来进行一些分析.现在我需要php来调用python代码并检索python代码提供的输出.两个文件都在同一个服务器上,但不在同一个文件夹中.我当前的方法不起作用,如下所示:$cmd = "/usr/bin/python /var/www/include/sCrape.py -u '$my_url' "; $response = shell_exec($cmd); $response = json_decode($response, true);现在当我尝试打印$response时,我得到了NULL对象(...

Shell_exec php与nohup【代码】

我认为有很多类似的帖子,但我在搜索后还没有找到解决方案. 基本上,我正在尝试在后台运行两个脚本.当我在命令行中运行它们时,我在调用我的第一个脚本后看到:/usr/bin/nohup php script.php > nohupoutput.log & echo $!我试过了…… script.php> / dev / null&结果相同.我明白了:/usr/bin/nohup: ignoring input and redirecting stderr to stdout我忽略并运行第二个.我注意到它似乎挂在那里,按Enter键让我回到机器:?文件夹>/usr...

php – 安全执行shell脚本;在执行之前逃避变种【代码】

让我们假设我们有一个简单的PHP脚本应该从$_GET数组中获取ssh_host,ssh_username,ssh_port并尝试使用此参数连接到SSH.$port = escapeshellcmd($_GET['ssh_port']); $host = escapeshellcmd($_GET['ssh_host']); $username = escapeshellcmd($_GET['ssh_username']);$answer = shell_exec("ssh -p " . $port . " " . $user . "@" . $host);是escapeshellcmd()还是我需要更棘手的东西?或者也许我应该在这个例子中使用esc...

linux – 将PHP CLI打印的值分配给shell变量【代码】

我想要与assigning value to shell variable using a function return value from Python中给出的解决方案相当的PHP 在我的php文件中,我读了一些像这样的常量值: – $neededConstants = array("BASE_PATH","db_host","db_name","db_user","db_pass"); foreach($neededConstants as $each) {print constant($each); }在我的shell脚本中,到目前为止我有这个代码: – function getConfigVals() {php $PWD'/developer.php'//How to c...

php – shell_exec()在“ls”上返回null【代码】

所以我有这个代码,我只是想在另一个目录中创建一个列表,其中php脚本位于xampp文件夹中,保存到这个路径/ root / files / saves:<html> <body> <?php $output = shell_exec('ls /root/files/saves'); echo "<pre>$output</pre>"; ?> </body> </html>我不知道为什么我不能让它在var_dump上工作似乎输出是null我真的很困惑它应该工作或我只是它都错了我需要一些帮助.解决方法:在shell命令的末尾添加2>& 1以返回STDERR以及STDOUT.$outp...

PHP中的system(),exec()和shell_exec()有什么区别?【代码】

可以通过三个PHP函数运行外部命令system(); exec(); shell_exec();但他们的区别是什么?尽管它们具体应用,但在大多数情况下,可以同样使用.我很想知道哪些是可以同样使用的首选.例如,对于解压缩文件或压缩文件夹(使用tar命令),哪一个是首选(可能从性能的角度来看)? 更新:在另一个问题中,我发现了一个非常有用的link,描述了这些功能的不同方面.我在这里分享链接,因为其他人可能会用来更好地了解安全问题和其他方面.解决方法:exec ...

shell_exec中的PHP sudo【代码】

我想用root_exec以root身份执行命令.现在我知道这很危险,但请相信我,您需要使用MOD_AUTH登录并拥有正确的权限来访问此页面.这很安全.我怎么能这样做?解决方法:您可以使用最新的SVN版本phpseclib, a pure PHP SSH implementation来执行此操作.例如.<?php include('Net/SSH2.php');$ssh = new Net_SSH2('www.domain.tld'); $ssh->login('username', 'password');$ssh->read('[prompt]'); $ssh->write("sudo command\n"); $ssh->read...

php_addslashes绕过与写入文件配置getshell【代码】

绕过addslashes并写入文件配置getshelladdslashes函数利用 写入配置getshell与addslashes绕过: <?php $str = addslashes($_GET['option']); $file = file_get_contents('xxxxx/option.php'); $file = preg_replace('|\$option=\'.*\';|', "\$option='$str';", $file); file_put_contents('xxxxx/option.php', $file); ?>对option变量进行了addslashes函数的限制,但是后面使用了file_get_contents函数打开文件,中间使用preg_repl...

将多个PHP变量传递给shell_exec()?【代码】

我使用shell_exec方法从PHP调用test.sh.$my_url="http://www.somesite.com/"; $my_refer="http://www.somesite.com/"; $page = shell_exec('/tmp/my_script.php $my_url $my_refer');但是,命令行脚本说它只收到一个参数:/tmp/my_script.php 当我将呼叫更改为: 码:$page = shell_exec('/tmp/my_script.php {$my_url} {$my_refer}');它说它接收了3个参数,但是argv [1]和argv [2]是空的. 当我将呼叫更改为: 码:$page = shell_exe...

php shell_exec()输出来获取文本文件【代码】

我正在尝试在我的Centos计算机上运行rate -c 192.168.122.0/24命令,并使用shell_exec(‘rate -c 192.168.122.0/24’)命令将该命令的输出写入文本文件;还是没有运气!!解决方法:如您忘记提及的那样,您的命令提供了一个非结束输出流.要实时读取输出,您需要使用popen. 来自PHP网站的示例:$handle = popen('/path/to/executable 2>&1', 'r'); echo "'$handle'; " . gettype($handle) . "\n"; $read = fread($handle, 2096); echo $read...

PHP exec / shell_exec / system无法通过浏览器工作【代码】

我正在运行一个带有apache版本1.3.33和PHP版本4.4的SCO Unix盒子.我可以通过cli正确执行exec命令,但是在尝试通过浏览器执行脚本时会遇到麻烦.我的设置是: >安全模式关闭>完全读/写/执行权限>显示所有错误>没有禁用功能 我的代码:htdocs目录中的test_script.php<?php exec('ls',$out,$rval); echo "Output:<hr />"; print "<pre>"; print_r($out); print "</pre>"; echo "Return Value:<hr />"; echo $rval; ?>我也尝试过显式设置...

SYSTEM - 相关标签
命令行 - 相关标签