导航:首页 > 编程语言 > phpexecpath

phpexecpath

发布时间:2022-05-02 09:47:02

php怎么运行DOS命令

你的意思应该是在DOS环境下运行php命令。
首先,将php加入到环境变量path中。
然后,执行:php 你要执行的命令。

⑵ 关于一个php exec函数的问题 bat文件能运行 但是接下来的字符串打印不出来

exec('c:/aaa/bbb.bat');
exec就等于你直接在cmd敲命令回车,你在cmd敲一下start
c:/aaa/bbb.bat
你会发现再弹出一个cmd窗口,这应该就是一直加载中的原因了
exec也可以把执行的结果全部返回到$output函数里(数组),$status是执行的状态
0为成功
1为失败
$a
=
exec("dir",$out,$status);
print_r($a);
print_r($out);
print_r($status);

⑶ php exec在linux执行 jdk没一点反应

先说我认为最有可能的问题吧
请在后面加上这句exec("exit(0)");
这个是针对你指令里的 >

然后猜测下还有什么可能的问题吧
usr/java/jdk1.6.0_23/bin/ 这个path是不是没给access的权限?可以试着把jar js文件复制到现在的目录下,再试下看看问题是不是在这(不好意思,没试过楼主这种写法,java安装好在哪里用都是java就好了吧,为什么特意给path呢)
顺便纠正个小问题吧
$print_r($o);这个前面多了个$,还请楼主仔细检查啊,不要最后发现是这么个粗心问题造成的
建议楼主试下
exec('java -version',$o);
print_r($o);
(因为我这里echo $JAVA_HOME是什么也不显示的..)
还有什么呢
关于path还可以试下apache_lookup_uri
--------------------------------------------------------------------
那段我用的是给你看个例子,如果你用的话要改的...(不会直接用了吧orz)
你把yuicompressor-2.4.2.jar test.js 复制到现在的目录下
代码这样
exec("java java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 -v test.js > packed.js",$output,$status);
exec("exit(0)");
//chmod("packed.js",0644);//如果你需要的话在把这句加上
echo "<h4 style='color:#CC0000'>Error</h4>\n",
join("\n",$output);
还有楼主你不仔细看回答啊$print_r($o);这句你多打了$,是错的,快点从代码里删除吧....

⑷ 菜鸟求助 396系统错误

PHP执行系统命令(简介及方法)
在PHP中调用外部命令,可以用如下三种方法来实现:
方法一:用PHP提供的专门函数(四个):
PHP提供4个专门的执行外部命令的函数:exec(), system(), passthru(), shell_exec()
1)exec()
原型: string exec ( string $command [, array &$output [, int &$return_var ]] )
说明: exec执行系统外部命令时不会输出结果,而是返回结果的最后一行。如果想得到结果,可以使用第二个参数,让其输出到指定的数组。此数组一个记录代表输出的一行。即如果输出结果有20行,则这个数组就有20条记录,所以如果需要反复输出调用不同系统外部命令的结果,最好在输出每一条系统外部命令结果时清空这个数组unset($output),以防混乱。第三个参数用来取得命令执行的状态码,通常执行成功都是返回0。
<?php
exec("dir",$output);
print_r($output);
?>
2)system()
原型: string system ( string $command [, int &$return_var ] )
说明: system和exec的区别在于,system在执行系统外部命令时,直接将结果输出到游览器,如果执行命令成功则返回true,否则返回false。第二个参数与exec第三个参数含义一样。
<?php
system("pwd");
?>
3)passthru()
原型: void passthru ( string $command [, int &$return_var ] )
说明: passthru与system的区别,passthru直接将结果输出到游览器,不返回任何值,且其可以输出二进制,比如图像数据。第二个参数可选,是状态码。
<?php
header("Content-type:image/gif");
passthru("/usr/bin/ppm2tiff /usr/share/tk8.4/demos/images/teapot.ppm");
?>
4)shell_exec()
原型: string shell_exec ( string $cmd )
说明: 直接执行命令$cmd
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
方法二:反撇号
原型: 反撇号`(和~在同一个键)执行系统外部命令
说明: 在使用这种方法执行系统外部命令时,要确保shell_exec函数可用,否则是无法使用这种反撇号执行系统外部命令的。
<?php
echo `dir`;
?>
方法三:用popen()函数打开进程
原型: resource popen ( string $command , string $mode )
说明: 能够和命令进行交互。之前介绍的方法只能简单地执行命令,却不能与命令交互。有时须向命令输入一些东西,如在增加系统用户时,要调用su来把当前用户换到root用户,而su命令必须要在命令行上输入root的密码。这种情况下,用之前提到的方法显然是不行的。
popen( )函数打开一个进程管道来执行给定的命令,返回一个文件句柄,可以对它读和写。返回值和fopen()函数一样,返回一个文件指针。除非使用的是单一的模式打开(读or写),否则必须使用pclose()函数关闭。该指针可以被fgets(),fgetss(),fwrite()调用。出错时,返回FALSE。
<?php
error_reporting(E_ALL);
/* Add redirection so we can get stderr. */
$handle = popen('/path/to/executable 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>
要考虑两个问题:安全性和超时
1)安全性
由于PHP基本是用于WEB程序开发的,所以安全性成了人们考虑的一个重要方面 。于是PHP的设计者们给PHP加了一个门:安全模式。如果运行在安全模式下,那么PHP脚本中将受 到如下四个方面的限制:
执行外部命令
在打开文件时有些限制
连接MySQL数据库
基于HTTP的认证
在安全模式下,只有在特定目录中的外部程序才可以被执行,对其它程序的调用将被拒绝。这个目录可以在PhP.ini 文件中用safe_mode_exec_dir指令,或在编译PHP是加上--with-exec-dir选项来指定。
当你使用这些函数来执行系统命令时,可以使用escapeshellcmd()和escapeshellarg()函数阻止用户恶意在系统上执行命令,escapeshellcmd()针对的是执行的系统命令,而escapeshellarg()针对的是执行系统命令的参数。这两个参数有点类似addslashes()的功能。
2)超时
当执行命令的返回结果非常庞大时,可以需要考虑将返回结果输出至其他文件,再另行读取文件,这样可以显着提高程序执行的效率。
如果要执行的命令要花费很长的时间,那么应该把这个命令放到系统的后台去运行。但在默认情况下,象system()等函数要等到这个命令运行完才返回(实际上是在等命令的输出结果),这肯定会引起PHP脚本的超时。解决的办法是把命令的输出重定向到另外一个文件或流中,如:
<?php
system("/usr/local/bin/order_proc > /tmp/abc ");
?>
但我调用的DOS命令需要几分钟的时间,而且为了批处理不能简单的把结果写入文件了事,要顺序执行以下的程序
PHP设置了调用系统命令的时间限制,如果调用命令超时,虽然这个命令还是会被执行完,但PHP没有得到返回值,被终止了(最可恨的是,不显示任何错误)
修改php.ini并重启Apache以允许系统命令运行更长的时间
max_execution_time = 600
我的程序是后台运行的,逻辑OK就成了

⑸ 我要在php中调用system或者exec执行一个程序

exec应该可以的,但是根据命令特征你可能需要结合使用sleep方法,例如:
exec('D:');
sleep(1);
exec('cd D:\\path\\path', $cmd); //反斜杠要转义哦
sleep(1);
if (! empty($cmd)) {
//$cmd 保存的是命令执行后的屏幕输出,针对cd这条命令,如果有输出肯定是错误信息

die($cmd);

}
exec('xelatex test.tex', $cmd);

⑹ 为什么php 执行linux 命令不成功 shell_exec('unoconv -f pdf aa.doc')

我也刚遇到这个问题,不过我解决了。你试着加载PATH参数在命令行前边,就是把 echo $PATH 的结果都添加到 unoconv -f pdf aa.doc 前面。

⑺ php(exec,system)执行外部程序问题!!

Fedora 12 是SELinux, Security Enhanced Liux. 安全性特别加强. 由你的描述来看, 应该是SELinux的权限没打开.
在/etc/selinux/config 中将 SELINUX=enforcing 改成 SELINUX=disable即可, 如此便将SELinux中强化安全的部分完全关闭, 但也就变得和一般linux没多少差别. 改完后要reboot.
如果想要SELinux的安全功能又想达成你要的目的, 要参考 SELinux特有的chcon指令以及httpd_selinux语法.
例如,
chcon -R -t httpd_user_content_t /web

⑻ php exec("javac/java")问题

根据提示信息,你试一下下面的方法

1.配置操作系统的环境变量右击我的电脑->属性->高级选项卡->环境变量

配置系统环境变量的Path编辑它,给它加上一句

C:Javajdk1.6.0_21in(这是javac.exe文件在目录);

这可以是解决javac不是内部或外部命令的问题;

2.配置环境变量classpath在最前面加一个.;

⑼ PHP调动linux底层命令问题 我想用exec代码得到网络借口IP 掩码

php许多底层指令在网络服务端会被屏蔽,如果需要使用可先咨询一下网站服务提供商。 追问: 忘了说明了, win7 系统 虚拟机搭建ubuntu 服务器搭建在ubuntu下的 我应该没有禁用任何任何网络服务端 回答: 注意执行文件的路径 补充: exec (PHP 3, PHP 4 ) exec -- Execute an external program Descriptionstring exec ( string command [, array output [, int return_var]]) exec() executes the given command, however it does not output anything. It simply returns the last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. If the output argument is present, then the specified array will be filled with every line of output from the command. Line endings, such as \n, are not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec() . If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable. 例子1. An exec() example <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?> 警告 If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands. 注: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends. 注: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable. 警告 With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". See also system() , passthru() , popen() , escapeshellcmd() , and the backtick operator. 追问: EXEC我已经看过无数次了 在手册上 你说的文件路径是指什么? 我想知道 这个命令之所以什么都没有返回是不是 权限问题? 追问: 谢谢 最后绝对路径解决了问题 /sbin/ifconfig 谢啦

⑽ PHP中的安全模式是指的什么

手册如是说: 章 24. 安全模式目录 被安全模式限制或屏蔽的函数 php 的安全模式是为了试图解决共享服务器(shared-server)安全问题而设立的。在结构上,试图在 php 层上解决这个问题是不合理的,但修改 web 服务器层和操作系统层显得非常不现实。因此许多人,非凡是 isp,目前使用安全模式。 表格 24-1. 控制安全模式的设置选项有: 设置选项 默认值 safe_mode off safe_mode_gid 0 safe_mode_include_dir safe_mode_exec_dir 1 open_basedir safe_mode_allowed_env_vars php_ safe_mode_protected_env_vars ld_library_path disable_functions 当 safe_mode 设置为 on,php 将检查当前脚本的拥有者是否和将被文件函数操作的文件的拥有者相匹配。例如: -rw-rw-r-- 1 rasmus rasmus 33 jul 1 19:20 script.php -rw-r--r-- 1 root root 1116 may 26 18:01 /etc/passwd 运行 script.php <?php 假如安全模式被激活,则将会导致以下错误: warning: safe mode restriction in effect. the script whose uid is 500 is not allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2 同时,或许会存在这样的环境,在该环境下,宽松的 gid 检查已经足够,但严格的 uid 检查反而是不适合的。您可以用 safe_mode_gid 选项来控制这种检查。假如设置为 on 则进行宽松的 gid 检查;设置为 off(默认值)则进行 uid 检查。 除了 safe_mode 以外,假如您设置了 open_basedir 选项,则所有的文件操作将被限制在您指定的目录下。例如: <directory /docroot php_admin_value open_basedir /docroot </directory 假如您在设置了 open_basedir 选项后运行同样的 script.php,则其结果会是: warning: open_basedir restriction in effect. file is in wrong directory in /docroot/script.php on line 2 您也可以单独地屏蔽某些函数。

阅读全文

与phpexecpath相关的资料

热点内容
职业生涯pdf 浏览:953
ubuntu安装软件php 浏览:158
黑马程序员退学流程 浏览:361
网页服务器崩溃怎么回事 浏览:650
cnc编程前景怎么样 浏览:319
lniux命令详解 浏览:493
linuxmysql查询日志 浏览:368
老捷达伙伴压缩比 浏览:93
改后缀加密 浏览:432
邮局选址问题算法 浏览:14
河北服务器内存云主机 浏览:12
在电脑上怎么找到加密狗图标 浏览:435
电脑的浏览器怎么打开pdf文件怎么打开 浏览:142
pdf卡片库下载 浏览:11
单片机中二进制表示什么 浏览:725
java网络编程推荐 浏览:795
施耐德开关编程 浏览:66
组织胚胎学pdf 浏览:844
linux查看发包 浏览:496
加密货币交易所暴利时代 浏览:824