2

新代码:

<?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"));  
4

1 回答 1

3

我会放弃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);

这可能会或可能不会解决在符号中带有单括号 ( ') 和空格 ( ) 的某些系统上的某些问题。

于 2013-07-06T15:27:11.560 回答