array("pipe", "w"), // stdout 2 => array("pipe-6ren">
gpt4 book ai didi

PHP SVN 更新 - TortoiseSVN

转载 作者:可可西里 更新时间:2023-11-01 10:06:52 25 4
gpt4 key购买 nike

新代码:

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

最佳答案

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

这可能会或可能不会解决某些系统上的一些问题,这些系统在符号中使用单个括号 (') 和空格 () 会出现问题。

关于PHP SVN 更新 - TortoiseSVN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17388589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com