如何在ProcessStartInfo()中使用参数

时间:2015-08-28 10:14:47

标签: c# python processstartinfo

我正在尝试编写以下代码以在c#中运行python脚本: -

if ({Of Procs}="") then "0"
else {Of Procs}

在上面的 ProcessStartInfo startinfo = new ProcessStartInfo(); startinfo.FileName = @"C:\Program Files (x86)\PuTTY\plink.exe"; startinfo.Arguments = "-ssh username@lpl250srd01 -pw pass /home/abc/dComponents/bin/python eggs/beans/EGG-INFO/scripts/beanstalktop.py"; 之间有一个空格,这意味着我需要执行"python eggs"文件,但c#将其作为python目录,egg作为单独的目录,并抛出错误。

任何人都可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

您必须转义参数文件路径,如:

        ProcessStartInfo info = new ProcessStartInfo("notepad.exe");
        info.Arguments = "\"c:\\temp\\test test\\test.txt\"";
        Process.Start(info);

答案 1 :(得分:0)

这么简单:)

        Process process = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                CreateNoWindow = false,
                UseShellExecute = true,
                FileName = "pythonFile.py",
                WindowStyle = ProcessWindowStyle.Normal,
                Arguments = "-sk server -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer"
            }
        };
        process.Start();
        // this line waits till the python file is
        // finished and then resumes the code
        process.WaitForExit();