1

I am trying to code the following to run a python script in c# :-

 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";

In the above there is a space between "python eggs" which means i need to execute the .py file but c# takes it as python directory and eggs as seperate directory and throws me an error.

Can any one help me in solving this??

Viraj Nalawade
  • 3,137
  • 3
  • 28
  • 44

2 Answers2

1

You have to escape the arguments file path like:

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

as simple as this :)

        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();
GaziWay
  • 51
  • 3