在 C# 中使用 Drush 站点安装 [英] Using Drush Site-Install in C#

查看:24
本文介绍了在 C# 中使用 Drush 站点安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 C# 中的 Drush 进行 Drupal 站点安装,作为使用 MSI 的完整 Windows Server 站点安装的一部分.我正在使用的 Drush 命令如下.

I'm trying to do a Drupal site install using Drush in C# as part of a full Windows Server site installation using MSI. The Drush commmand I am using is the following one.

C:ProgramDataDrushDrush.bat -y si application_name --db-url=sqlsrv://admin_name:password(local)SQLEXPRESS:/database_name --account-name=admin --account-mail=name@test.com --account-pass=Password1234 --site-mail="admin@company.com" --site-name="Site Name" install_configure_form.site_default_country=GB install_configure_form.date_default_timezone="Europe/London"

当在工作目录 (inetpubapplication_name) 中从 cmd.exe 运行时,这可以完美运行.

And this works perfectly when run from cmd.exe when in the working directory (inetpubapplication_name).

在安装过程中将上述内容写入代码并执行时会出现问题,并且总是导致以下错误(每次都有不同的文件名).

The issue arises when the above is put into code and executed during an installation and always results in the following error (with a different file name each time).

无法解压 C:ProgramDataDrushlibdruFD63.tmp.gz

Unable to decompress C:ProgramDataDrushlibdruFD63.tmp.gz

用于执行命令的 C# 代码如下:

The C# code being used to execute the command is as follows:

public static ActionResult Drush_Configuration(Session session)
    {       
        string strArgs = "-y si application_name --db-url=sqlsrv://admin_name:password(local)SQLEXPRESS:/database_name --account-name=admin --account-mail=name@test.com --account-pass=Password1234 --site-mail="admin@company.com" --site-name="Site Name" install_configure_form.site_default_country=GB install_configure_form.date_default_timezone="Europe/London";
        string strExeCmd = @"C:ProgramDataDrushDrush.bat ";
        strExeCmd = strExeCmd + strArgs;
        string strLocation = @"C:inetpubapplication_name";

        session.Log("Starting Drush Configuration");
        session.Log("Command line is: " + strExeCmd + " " + strArgs);

        int exitCode;
        ProcessStartInfo processInfo;
        Process process;
        try
        {
            processInfo = new ProcessStartInfo("cmd.exe", "/c " + strExeCmd);
            processInfo.WorkingDirectory = strLocation;
            processInfo.WindowStyle = ProcessWindowStyle.Normal;
            processInfo.CreateNoWindow = true;
            processInfo.UseShellExecute = false;
            // *** Redirect the output ***
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;

            process = Process.Start(processInfo);
            process.WaitForExit();

            // *** Read the streams ***
            string output = process.StandardOutput.ReadToEnd();
            string error = process.StandardError.ReadToEnd();

            exitCode = process.ExitCode;

            session.Log("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
            session.Log("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
            session.Log("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
            process.Close();
        }
        catch (Exception e)
        {
            session.Log("Error: " + e);
            return ActionResult.Failure;
        }

        session.Log("Drush Configuration completed successfully");
        return ActionResult.Success;
    }

并且如上所述,这总是导致无法解压缩"错误.

And as stated above, this always results in the "unable to decompress" error.

有没有人在 Drush 中使用过 c# 来运行 Site-Install?有谁知道为什么以这种方式执行时可能会失败?

Has anyone ever used c# to run Site-Install in Drush? Does anyone know why this might fail when executed in this way?

任何想法或建议将不胜感激.

Any thoughts or advice would be greatly appreciated.

我使用的是 Drush-5.8-2012-12-10-Installer-v1.0.20、Drupal 7 和 Windows Server 2008 R2 x64.

I am using Drush-5.8-2012-12-10-Installer-v1.0.20, Drupal 7, and Windows Server 2008 R2 x64.

推荐答案

此问题的原因是环境变量.Drush MSI 安装程序设置了在 MSI 机器上下文中无法识别的用户路径环境变量.
因此,通过将 Drush、GnuWin32 和 PHP 的系统路径变量添加到站点安装 MSI,可以以编程方式安装站点.

The cause of this issue was the Environment Variables. The Drush MSI installer sets up User Path Environment Variables which are not recognized in an MSI machine context.
So, by adding System Path Variables for Drush, GnuWin32 and PHP to the site-install MSI the site can be programmatically installed.

这篇关于在 C# 中使用 Drush 站点安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆