0

First of all I do not know if it is a bad practice to call python script from c# so if this is the case please tell me.My current problem is as follows.

MY c# code only runs the python script partially....

means (python script create only 4 files when it is supposed to create 10 files)

But When I run my script from cmd in windows I see complete functionality....

Another thing I saw is when I stop my Visual Studio(2013) I see the complete functionality

I am calling the python script(main.py) from c# like this...

   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);
                }
            }

    }

Why I am getting complete script functionality when I stop in Visual Studio(2013)??

Amrit
  • 2,115
  • 1
  • 21
  • 41

1 Answers1

0

I dont understand you motivation behind this. But why dont you use IronPython which is excellent addition to the .NET Framework, providing Python developers with the power of the .NET framework.

Ashishkumar
  • 30
  • 1
  • 6
  • Yes,I would like to use iron python but it does not support scrapy framework apparantly.I got this from this link https://stackoverflow.com/questions/23511569/net-framework-with-scrapy-python . – Amrit Dec 28 '17 at 07:57