简体   繁体   中英

launch python program with arguments from c#

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:

在此处输入图片说明

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?

我通过授予每个人访问包含 python.exe 的文件夹的权限解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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