C#代码不能在visual studio中运行完整的python脚本

问题描述 投票:0回答:1

首先,我不知道从c#调用python脚本是不是一个坏习惯,所以如果是这种情况请告诉我。我目前的问题如下。

我的c#代码只运行部分python脚本....

表示(python脚本在创建10个文件时只创建4个文件)

但是,当我从Windows中的cmd运行我的脚本时,我看到完整的功能....

我看到的另一件事是当我停止我的Visual Studio(2013)时,我看到了完整的功能

我从c#调用python脚本(main.py)就像这样......

   public JsonResult FetchscrapyDataUrl(String website)
        {

           ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = @"C:\ProgramData\Anaconda3\python.exe";            
            start.Arguments = @"C:\Users\PycharmProjects\scraping_web\scrape_info\main.py";
           //this is path to .py file from scrapy project

            start.CreateNoWindow = false;  // We don't need new window
            start.UseShellExecute = false;  // Do not use OS shell
            //start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
            start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
            Console.WriteLine("Python Starting");


            start.RedirectStandardOutput = true;
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
                    string result = reader.ReadToEnd();  // Here is the result of StdOut(for example: print "test")
                    Console.Write(result);
                }
            }

    }

为什么我在Visual Studio(2013)中停止时获得完整的脚本功能?

c# python visual-studio process
1个回答
0
投票

我不明白你背后的动机。但是为什么不使用IronPython,这是.NET Framework的优秀补充,为Python开发人员提供了.NET框架的强大功能。

© www.soinside.com 2019 - 2024. All rights reserved.