2017-11-04 4 views
0

Zunächst einmal weiß ich nicht, ob es eine schlechte Praxis ist, Python-Skript von C# aufzurufen, wenn dies der Fall ist bitte sagen Sie mir.Mein aktuelles Problem ist wie folgt.C# -Code nicht vollständige Python-Skript in Visual Studio

MY C# -Code läuft nur den Python-Skript zum Teil ....

Mittel (Python-Skript erstellen nur 4-Dateien, wenn es soll 10 Dateien erstellen)

Aber wenn ich laufe mein Skript von cmd in Fenstern sehe ich die Funktionalität ....

Eine andere Sache, die ich sah, wenn ich mein Visual Studio stoppen (2013) I die komplette Funktionalität

ich rufe den python scr sehen ipt (main.py) von C# so ...

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

    } 

Warum erhalte ich vollständige Skript-Funktionalität, wenn ich in Visual Studio (2013) zu stoppen ??

+0

Was meinst du mit teilweise? –

+0

Haben Sie versucht, 'process.WaitForExit()' aufzurufen? – pinkfloydx33

+0

@JohnEphraimTugado Ich meine, dass das Skript nicht seine vollständige Funktionalität ausführen, wie es sollte. – amrit

Antwort

0

Ich verstehe Sie Motivation dahinter nicht. Aber warum verwenden Sie nicht IronPython, das eine hervorragende Ergänzung zu .NET Framework darstellt und Python-Entwicklern die Leistungsfähigkeit des .NET-Frameworks bietet?

+0

Ja, ich würde gerne Eisen Python verwenden, aber es nicht unterstützt scrapy Rahmen apparently.I habe dies von diesem Link https://StackOverflow.com/Questions/23511569/net-framework-with-Scracy-Python. – amrit