简体   繁体   English

控制第二个cmd窗口-C#

[英]Controlling 2nd cmd window - c#

I am trying to use DB2's Command Line processor. 我正在尝试使用DB2的命令行处理器。 When using it on the command line, I enter: db2cmd then a 2nd window opens where I can connect to the database and submit queries. 在命令行上使用它时,我输入:db2cmd,然后打开第二个窗口,我可以在其中连接到数据库并提交查询。 I am attempting to write a wrapper for the CLP and when I access the command line, it opens the DB2 CLP in a 2nd window and I can't figure out how to send arguements to the new window. 我试图为CLP写一个包装器,当我访问命令行时,它在第二个窗口中打开DB2 CLP,但我不知道如何将争论发送到新窗口。 Here is what I have: 这是我所拥有的:

    static void Main(string[] args)
    {
        var p = new Process();
        var info = new ProcessStartInfo();
        info.FileName = "db2cmd";
        info.RedirectStandardInput = true;
        info.UseShellExecute = false;
        info.CreateNoWindow = true;

        p.StartInfo = info;
        p.Start();

        using (var sw = p.StandardInput)
        {
            sw.WriteLine("DB2 CONNECT TO dbname USER \"username\" USING \"password\"");
            sw.WriteLine("DB2 SELECT * FROM SPYPRD.CLMDTL FETCH FIRST 10 ROWS ONLY");
        }
    }

Maybe better to use an alternative interface (eg the ADO .net interface) from C# instead of using the CLP. 最好使用C#的替代接口(例如ADO .net接口),而不是使用CLP。

To use commands like LOAD and EXPORT etc, from ADO (or jdbc/odbc etc) you invoke them via stored procedure SYSPROC.ADMIN_CMD() if the Db2-server runs on Linux/Unix/Windows. 要使用ADO(或jdbc / odbc等)中的LOAD和EXPORT等命令,如果Db2服务器在Linux / Unix / Windows上运行,则可以通过存储过程SYSPROC.ADMIN_CMD()调用它们。 Pay attention to the details in the documentation for that stored procedure because all file names are relative to the Db2-server (not the workstation). 请注意该存储过程的文档中的详细信息,因为所有文件名都是相对于Db2服务器(而不是工作站)的。

Not sure if CLP accepts stdin redirection for passwords - you would also need to parse the stdout, maybe messy. 不知道CLP是否接受stdin重定向的密码-您还需要解析stdout,也许很麻烦。

If the database is local then you can use the CLP without needing a userid/password on the CONNECT statement. 如果数据库是本地数据库,则可以使用CLP,而无需在CONNECT语句上使用用户ID /密码。 If you wish to connect with different credentials use runAs to specify the credentials independently of the CLP, to avoid needing to send arguments to the CLP. 如果希望使用不同的凭据进行连接,请使用runA独立于CLP来指定凭据,以避免需要向CLP发送参数。

If the database is remote and is on Linux/Unix/Windows, best to use an alternative interface than CLP (eg ADO etc), or consider shipping the script to the remote-server to run locally on the Db2-LUW server as the required-user again avoiding passwords(eg if the Db2-server runs on Linux/Unix/Windows, use tools equivalent to psexec or ssh etc). 如果数据库是远程数据库,并且在Linux / Unix / Windows上,则最好使用CLP以外的替代接口(例如ADO等),或考虑将脚本传送到远程服务器以根据需要在Db2-LUW服务器上本地运行-user再次避免使用密码(例如,如果Db2服务器在Linux / Unix / Windows上运行,请使用与psexec或ssh等价的工具)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM