新代码:
<?php
exec('"C:\Program Files\TortoiseSVN\bin\svn.exe" update "c:\wamp\www\project"');这将导致无限循环,不返回任何结果。我做错了什么?
==编辑==
在Windows上,我试图使用PHP更新一个项目。我在使用命令行时遇到了问题:我想要视觉反馈(在冲突情况下很重要),所以我不想从后台进程开始。这个是可能的吗?
到目前为止,我的代码是:
<?php
$todo = "cd \"C:\\Program Files\\TortoiseSVN\\bin\\\"";
$todo2 = "START TortoiseProc.exe /command:update /path:\"C:\\wamp\\www\\project\\\" /closeonend:0";
pclose(popen($todo, "r"));
pclose(popen($todo2, "r")); 发布于 2013-07-06 15:27:11
我将删除exec并使用proc_open (参见http://php.net/manual/en/function.proc-open.php)。
下面是我迅速提出的一个例子,它应该适用于您:
<?php
// setup pipes that you'll use
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
// call your process
$process = proc_open('"C:\Program Files\TortoiseSVN\bin\svn.exe" update "c:\wamp\www\project"',
$descriptorspec,
$pipes);
// if process is called, pipe data to variables which can later be processed.
if(is_resource($process))
{
$stdin = stream_get_contents($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$return_value = proc_close($process);
}
// Now it's up to you what you want to do with the data you've got.
// Remember that this is merely an example, you'll probably want to
// modify the output handling to your own likings...
header('Content-Type: text/plain; charset=UTF-8');
// check if there was an error, if not - dump the data
if($return_value === -1)
{
echo('The termination status of the process indicates an error.'."\r\n");
}
echo('---------------------------------'."\r\n".'STDIN contains:'."\r\n");
echo($stdin);
echo('---------------------------------'."\r\n".'STDOUTcontains:'."\r\n");
echo($stdout);
echo('---------------------------------'."\r\n".'STDERR contains:'."\r\n");
echo($stderr);
?>撇开:
线
// call your process
$process = proc_open('"C:\Program Files\TortoiseSVN\bin\svn.exe" update "c:\wamp\www\project"',
$descriptorspec,
$pipes);也可以像这样逃出来
// call your process
$process = proc_open("\"C:\\Program Files\\TortoiseSVN\\bin\\svn.exe\" update \"c:\\wamp\\www\\project\"",
$descriptorspec,
$pipes);它可能解决或不可能解决某些系统上的问题,这些系统在符号中带有单括号(')和空格()。
https://stackoverflow.com/questions/17388589
复制相似问题