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 ??
Was meinst du mit teilweise? –
Haben Sie versucht, 'process.WaitForExit()' aufzurufen? – pinkfloydx33
@JohnEphraimTugado Ich meine, dass das Skript nicht seine vollständige Funktionalität ausführen, wie es sollte. – amrit