繁体   English   中英

从C#执行cassandra命令行

[英]execute cassandra command line from C#

我想从C#源代码执行cqlsh复制命令。 我想执行一个Python脚本,该脚本位于以下路径下:

C:\Program Files\DataStax Community\python\python.exe" "C:\Program Files\DataStax Community\apache-cassandra\bin\cqlsh.py

这将给我以下屏幕截图: 在此处输入图片说明

一旦进入cqlsh,我就可以运行命令“将emp复制到emp.csv”。这个想法是,我想从c#代码执行所有这些操作。 这是我所做的:

 try
            {

Process p = new Process(); // create process (i.e., the python program
            p.StartInfo.FileName = @"C:\Python27\python.exe";
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute = false; // make sure we can read the output from stdout
            p.StartInfo.Arguments = @"C:\Program Files\DataStax Community\apache-cassandra\bin\cqlsh.py" + " " + "-e copy key_space.emp to 'D:/emp.csv'"; // start the python program with two parameters
            p.Start(); // start the process (the python program)
            p.WaitForExit();

            }catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
                string strError = ex.Message;
            } 

没有异常被捕获,但是就结果而言什么也没有发生。 任何帮助,将不胜感激 。

我很确定您的问题出在这条线上:

bin\cqlsh.py" + " " + "copy emp to D:/emp.csv";

如果要从命令行运行此命令,则cqlsh将需要-e标志来执行命令。 在Windows中,它看起来像这样(假设键空间名称为“ your_keyspace”:

python bin\cqlsh.py -e "copy your_keyspace.emp to d:\emp.csv"

因此,要从您的过程中实际调用它,您将不得不转义双引号或仅使用单引号:

bin\cqlsh.py" + " " + "-e 'copy your_keyspace.emp to d:\emp.csv'";

暂无
暂无

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

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