-2

I want to launch python program with a bunch of arguments from c#. I tried the solution provided in the link: How do I run a Python script from C#? , but it was not working for me. I also tried

public void LaunchProgram(string filepath, string args)
        {
            Process p = new Process();
            p.StartInfo.FileName = "python.exe";
            p.StartInfo.UseShellExecute = true; ;
            p.StartInfo.Arguments = filepath + " " + args ;
            p.Start();
        }

However, it is not working either. I would like to know what is the right way to pass a bunch of parameters in this condition? Thanks!

Update: This code is actually part of the wcf service. I got error in the line "p.start();" with the following error:

enter image description here

However, if I put this code in the console application, it works fine. I would like to know whether I need to do something in the service code?

More Update:

I can solve the above problem "The system cannot find the file specified" now by specifying the full path of python. However, if I run my client call the service, my python script is not running and the code does not show me any error either. I would like to know what would the problem this time be? Besides, I would like to know whether there is any good way to debug this kind of problem?

Community
  • 1
  • 1
bunny
  • 1,797
  • 8
  • 29
  • 58
  • What are you seeing when you try to run this code? What parameters have you tried with your method? – Tom Elliott Jul 28 '15 at 20:53
  • What is the error you are getting? You may need to provide the full path to python.exe – Ron Beyer Jul 28 '15 at 20:53
  • I updated my question, thank you! – bunny Jul 29 '15 at 13:40
  • http://stackoverflow.com/questions/15921007/executing-python-script-from-c-sharp – earlymorningtea Jul 29 '15 at 13:49
  • I set my service has the permission to access the file, but still got the same error. – bunny Jul 29 '15 at 15:31
  • You shouldn't include file path in arguments – wingerse Aug 04 '15 at 13:15
  • My file path is the python file I need to run. For example, my python script is test.py and its path is C:\test.py. I would like to know why I should not include the file path? I also tried the python script without any argument, it has the same behavior too which is neither run nor show any error. – bunny Aug 04 '15 at 13:21

1 Answers1

0

I have solved the problem by give permission to everyone to access the folder where has python.exe.

bunny
  • 1,797
  • 8
  • 29
  • 58