如何从ssis调用cmd.exe并在命令行上执行命令



我正在使用SQL Server Integration Services(SSIS 2008)中的脚本任务在Windows命令行上运行命令。该命令只需用已知的文件名解密文件。

当我执行任务时,脚本任务框变绿色并报告成功运行,但是在检查文件时,我发现什么都没有发生。以下是我的代码。知道我在这里做错了什么吗?预先感谢您。

更新:我的目标是从C#SSIS脚本解密文件,并了解为什么下面的代码不这样做。我不关心任务框是绿色还是报告成功。

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Diagnostics;

    public void Main()
    {
        string DecryptCommand;
        var startInfo = new ProcessStartInfo
        {
            FileName = "cmd.exe",
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };
        DecryptCommand = "echo my_passphrase|gpg --batch --passphrase-fd 0 --decrypt-files      my_file_" + DateTime.Now.ToString("MMddyyyy") + ".pgp"; 
        var process = new Process { StartInfo = startInfo };
        process.Start();
        process.StandardInput.WriteLine("cd D:\Foo\Bar\EncryptedFiles");
        process.StandardInput.WriteLine(DecryptCommand);
        process.StandardInput.WriteLine("exit");
        process.WaitForExit();
    }
}

}

Dts.TaskResult = (int)ScriptResults.Success;

此行意味着当过程退出时,无论该过程返回是什么,您将始终返回true。相反

更进一步,是否有原因是您使用command.exe而不是执行批处理或VB脚本?这将使您对输出的更多控制。

编辑:至于为什么您的程序不按预期执行,您是否尝试过在输入后手动冲洗流?

最新更新