-->

使用C#Drush站点安装(Using Drush Site-Install in C#)

2019-08-07 02:37发布

我试图做一个Drupal站点安装在C#中使用Drush作为使用MSI完整的Windows Server站点安装的一部分。 我使用的Drush条命令是以下之一。

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"

而从CMD.EXE运行时,这个完美的作品时,在工作目录(的Inetpub \应用程序名称)。

当上述的安装过程中被放入代码并执行,结果总是在下面的错误(每次用不同的文件名)的问题出现。

无法解压缩C:\ ProgramData \ Drush \ LIB \ druFD63.tmp.gz

C#代码被用来执行命令如下:

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网站,安装? 没有人知道为什么,当以这种方式执行,这可能会失败?

任何想法或意见,将不胜感激。

我使用Drush-5.8-2012-12-10-安装-v1.0.20,Drupal的7和Windows Server 2008 R2 64位。

Answer 1:

这个问题的原因是环境变量。 该Drush MSI安装程序设置未在MSI机上下文识别的用户路径环境变量。
因此,通过增加对Drush,和的GnuWin32 PHP系统路径变量到现场安装MSI网站可以通过编程安装。



文章来源: Using Drush Site-Install in C#
标签: c# drupal drush