كيفية الحصول على سجل من العملية.ابدأ
-
18-09-2020 - |
سؤال
انا ذاهب الى بريكومبيلي ل asp.net التطبيق في بلدي مخصص ج # شكل.كيف يمكنني استرداد سجلات العملية والتحقق مما إذا كانت عملية ناجحة أم لا?
وهنا رمز بلدي
string msPath = "c:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\";
string msCompiler = "aspnet_compiler.exe";
string fullCompilerPath = Path.Combine(msPath, msCompiler);
msPath.ThrowIfDirectoryMissing();
fullCompilerPath.ThrowIfFileIsMissing();
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
WorkingDirectory = msPath,
FileName = msCompiler,
Arguments = "-p {0} -v / {1}"
.StrFormat(
CurrentSetting.CodeSource,
CurrentSetting.CompileTarget)
};
Process.Start(process);
شكراً!
المحلول
تعيين الخاص بك ProcessStartInfo.RedirectStandardOutput
إلى true
- سيؤدي هذا إلى إعادة توجيه جميع المخرجات إلى Process.StandardOutput
, ، وهو دفق يمكنك قراءته للعثور على جميع رسائل الإخراج:
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
WorkingDirectory = msPath,
RedirectStandardOutput = true,
FileName = msCompiler,
Arguments = "-p {0} -v / {1}"
.StrFormat(
CurrentSetting.CodeSource,
CurrentSetting.CompileTarget)
};
Process p = Process.Start(process);
string output = p.StandardOutput.ReadToEnd();
يمكنك أيضا استخدام OutputDataReceived
حدث بطريقة مشابهة لما @بهارات ك يصف في إجابته.
هناك خصائص/أحداث مماثلة ل StandardError
- سوف تحتاج إلى تعيين RedirectStandardError
إلى true
كذلك.
نصائح أخرى
في سجل التطبيق الخاص بك المصدر لحدث Errordatareceeed:
giveacodicetagpre.أي خطأ يتم إلقاؤه في التطبيق المستهدف كتابة البيانات في هذا.شيء من هذا القبيل:
giveacodicetagpre.لا تنتمي إلى StackOverflow