我一直很难获得"子流程"的输出(一个由我通过c#System.Diagnostics.Process监控的黑盒流程内部启动)
我接受了上一篇文章的回答: 这里.在那里你可以找到我经历过的细节.
此时,虽然我能够找到由process1.exe生成的ssh进程,但我正在监视.我无法将输出重定向到我的c#程序,因为它是一个"已在运行的进程",并且不是直接从C#启动的.
看来,您在System.Diagnostics.Process对象上设置的所有属性只有在从c#应用程序显式启动该进程时才会生效; 如果某个其他"非托管进程"已启动该进程,则设置此重定向无效,因为该进程已由未指定我需要的重定向的内容启动.
有没有办法重定向已经启动的进程的输出(一个程序启动的进程,我没有在启动此进程之前预先指定重定向的范围)?
如何使用System.Diagnostics.Process类在c#中使用计算机名称="someComputer"在远程计算机上启动进程?
我在那台远程计算机上创建了一个小型控制台应用程序,它只是将"Hello world"写入txt文件,我想远程调用它.
控制台应用程序路径:c:\ MyAppFolder\MyApp.exe
目前我有这个:
ProcessStartInfo startInfo = new ProcessStartInfo(string.Format(@"\\{0}\{1}", someComputer, somePath);
startInfo.UserName = "MyUserName";
SecureString sec = new SecureString();
string pwd = "MyPassword";
foreach (char item in pwd)
{
sec.AppendChar(item);
}
sec.MakeReadOnly();
startInfo.Password = sec;
startInfo.UseShellExecute = false;
Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)
我一直在"找不到网络路径".
我们有一个IIS WCF服务,它以另一个用户的身份启动另一个进程(app.exe).我完全控制了两个应用程序(现在这是一个开发环境).IIS应用程序池以我的身份运行,域用户(DOMAIN \nirvin),也是该框的本地管理员.第二个进程应该作为本地用户运行(svc-low).我正在System.Diagnostics.Process.Start(ProcessStartInfo)
用来启动这个过程.该过程成功启动 - 我知道因为没有抛出异常,我得到了一个进程ID.但是进程立即死亡,我在事件日志中看到如下错误:
错误应用程序名称:app.exe,版本:1.0.3.0,时间戳:0x514cd763
错误模块名称:KERNELBASE.dll,版本:6.2.9200.16451,时间戳:0x50988aa6
异常代码:0xc06d007e
故障偏移:0x000000000003811c
错误进程id:0x10a4
错误应用程序启动时间:0x01ce274b3c83d62d
错误的应用程序路径:C:\ Program Files\company\app\app.exe
错误模块路径:C:\ Windows\system32\KERNELBASE.dll
报告编号:7a45cd1c-933e-11e2-93f8-005056b316dd
错误包全名:
错误包相关的应用程序ID:
我已经在app.exe(现在)中进行了非常彻底的日志记录,因此我认为它不会在.NET代码中引发错误(不再).
这是真正令人讨厌的部分:我认为我只是启动了错误的进程,所以我Process.Start()
在一个愚蠢的WinForms应用程序中复制了我的调用并在机器上像我一样运行它,希望能够修改,直到我得到正确的参数.因此,当然这是第一次和每次都有效:我能够始终如一地启动第二个流程并使其按预期运行.它只从IIS启动不起作用.
我已经尝试过"以批处理作业登录"的svc-low权限,并且我已尝试授予自己"替换进程级别令牌"(在本地安全策略中)的权限,但似乎都没有任何区别.
救命!
起初app.exe是一个控制台应用程序.尝试启动是让conhost.exe在事件日志中生成错误,因此我将app.exe切换为Windows应用程序.这让conhost脱离了这个等式,但是留给我这里描述的情况.(通过这个问题引导了这条道路.)
ProcessStartInfo
我使用的对象如下所示:
new ProcessStartInfo
{
FileName = fileName,
Arguments = allArguments,
Domain = domainName,
UserName = userName,
Password = securePassword,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = false
//LoadUserProfile = true //I've done it with and without this set …
Run Code Online (Sandbox Code Playgroud) 是否有使用ETW记录异常的标准方法?
据我所知,唯一的方法是记录消息,可能还有内部异常消息,因为Exception类型没有强类型参数.
我需要在执行进程期间获取内存和CPU使用率(该进程有时可以运行超过30分钟).与任务管理器的值相比,我能够获得可用RAM,但CPU使用率不正确.难道我做错了什么?这是我的代码:
class Program
{
static List<float> AvailableCPU = new List<float>();
static List<float> AvailableRAM = new List<float>();
protected static PerformanceCounter cpuCounter;
protected static PerformanceCounter ramCounter;
static void Main(string[] args)
{
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
try
{
System.Timers.Timer t = new System.Timers.Timer(1200);
t.Elapsed += new ElapsedEventHandler(TimerElapsed);
t.Start();
Thread.Sleep(10000);
}
catch (Exception e)
{
Console.WriteLine("catched exception");
}
Console.ReadLine();
}
public static void TimerElapsed(object source, ElapsedEventArgs e) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Mac OSX Catalina 中 dtruss 进程,但是 dtrace 报告错误。
$ sudo dtruss whoami
dtrace: system integrity protection is on, some features will not be available
dtrace: failed to execute whoami: (os/kern) failure
Run Code Online (Sandbox Code Playgroud)
我基本上是想获得堆栈跟踪。任何人都可以提供有关完成此操作的指导吗?
谢谢
当我在命令行运行msbuild时,它在控制台中显示漂亮的颜色.
但是当我从C#中运行时Process.Start
,输出显示为黑白.我该如何保持颜色?
var info = new ProcessStartInfo("msbuild")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
using (var p = Process.Start(info) )
{
p.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data);
p.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
p.BeginErrorReadLine();
p.BeginOutputReadLine();
p.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)
而且,虽然我们在这里,但它比我Process.Start
之前 运行的重要BeginOutputReadLine
吗?输出会丢失吗?
动机,对于那些感兴趣的人.我工作的项目使用自定义构建工具(重新发明轮子imho).它使用msbuild但在复杂的间接层之后(上面的简化模型).Msbuild的有用颜色丢失了.我想保存它们.
我试图理解Trace.Write
vs Trace.TraceInformation
和应该使用哪个之间的区别.
我尝试配置traceOutputOptions
时间戳/日期时间.我只需要为我正在编写的每条消息添加时间戳.我得到的日期时间有点混乱,因为它在下一行中附加应用程序名称和较少用户友好的时间戳,如下所示.
ConsoleApplication1.exe Information: 0 : Hello - Trace!
DateTime=2011-01-31T14:26:11.1538509Z
ConsoleApplication1.exe Error: 0 : Hello - Trace!
DateTime=2011-01-31T14:26:11.1538509Z
Run Code Online (Sandbox Code Playgroud)
我所需要的就像是
2011-01-31 11:32 Information: Hello - Trace!
2011-01-31 11:33 Error: Hello - Trace!
Run Code Online (Sandbox Code Playgroud)
App.config
这样做有什么简单的方法吗?
我有一个工作角色,在开发中完美运行但在部署时不起作用."不起作用"是相当模糊的,但这真的是我必须继续,因为我没有看到任何错误或任何事情(事件日志中无论如何 - 也许还有其他地方我可以看).我在我的代码中添加了一些跟踪语句,我看到第一个出现了,但没有其他的.
WorkerRole代码:
public class WorkerRole : RoleEntryPoint
{
#region Member variables
private IWindsorContainer _container;
private IJob[] _jobs;
#endregion
#region Methods
public override bool OnStart()
{
ConfigureDiagnostics();
Trace.WriteLine("WorkerRole.OnStart()");
try
{
Initialize();
Trace.WriteLine("Resolving jobs...");
_jobs = _container.ResolveAll<IJob>();
StartJobs();
return base.OnStart();
}
catch (Exception ex)
{
TraceUtil.TraceException(ex);
throw;
}
finally
{
Trace.WriteLine("WorkerRole.OnStart - Complete");
Trace.Flush();
}
}
/// <summary>
/// Sets up diagnostics.
/// </summary>
private void ConfigureDiagnostics()
{
DiagnosticMonitorConfiguration dmc =
DiagnosticMonitor.GetDefaultInitialConfiguration();
dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc); …
Run Code Online (Sandbox Code Playgroud) 我有以下配置,但没有跟踪到Application Insights(否则Application Insights可以正常用于其他日志记录,Azure诊断侦听器也在工作并捕获跟踪).难道我做错了什么?
<system.diagnostics>
<trace autoflush="true" indentsize="0">
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
</add>
<add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
</listeners>
</trace>
</system.diagnostics>
Run Code Online (Sandbox Code Playgroud) system.diagnostics azure azure-diagnostics azure-application-insights