簡體   English   中英

C#代碼無法在Visual Studio中運行完整的python腳本

[英]C# code do not run complete python script in visual studio

首先我不知道從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)中停止時會獲得完整的腳本功能?

我不了解您的動機。 但是,為什么不使用IronPython,它是.NET Framework的出色補充,為Python開發人員提供了.NET Framework的強大功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM