在C#中使用Drush Site-Install [英] Using Drush Site-Install in C#

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

问题描述

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

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:\ProgramData\Drush\Drush.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"

当在工作目录(inetpub\application_name)中运行时从cmd.exe运行时,这可以很好地运行。

And this works perfectly when run from cmd.exe when in the working directory (inetpub\application_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:\ProgramData\Drush\lib\druFD63.tmp.gz

Unable to decompress C:\ProgramData\Drush\lib\druFD63.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:\ProgramData\Drush\Drush.bat ";
        strExeCmd = strExeCmd + strArgs;
        string strLocation = @"C:\inetpub\application_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;
    }

如上所述,这总是导致无法解压缩错误有没有人曾经使用c#在Drush中运行Site-Install呢?

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

有人知道为什么这样执行时可能会失败?

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的系统路径变量添加到site-install 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 Site-Install的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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