因为vsinstr -coverage hello.exe,我可以使用C#代码如下.
Process p = new Process();
StringBuilder sb = new StringBuilder("/COVERAGE ");
sb.Append("hello.exe");
p.StartInfo.FileName = "vsinstr.exe";
p.StartInfo.Arguments = sb.ToString();
p.Start();
p.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
当出现错误时,我收到错误消息:Error VSP1018: VSInstr does not support processing binaries that are already instrumented..
如何使用C#获取此错误消息?
我可以从答案中获取错误消息.
using System;
using System.Text;
using System.Diagnostics;
// You must add a reference to Microsoft.VisualStudio.Coverage.Monitor.dll
namespace LvFpga
{
class Cov2xml
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用PowerShell构建一个线程清理脚本,该脚本是从IIS启动的.我使用powershell远程处理创建了一个线程"由所有者杀死进程",从与清理脚本相同的服务器列表运行,这没有问题.
$jobs = @()
foreach ($comp in $comps) {
$jobs += start-job -FilePath ("CleanupJob.ps1") -ArgumentList $comp, $username
Write-Host "Started Job on: $comp"
}
foreach($job in $jobs)
{
$job | wait-job | out-null
receive-job $job.ID
}
Remove-Job -State Completed
Run Code Online (Sandbox Code Playgroud)
当我从powershell控制台运行我的脚本时,整个过程运行完美,主线程启动28个新进程,启动与每个服务器的远程连接,并等待所有作业完成.完成后,我得到输出,主机线程存在.全部按计划运行.
当我从我的asp.net应用程序运行它时不是这样,我为我的28个服务器中的每个服务器获得"开始工作:$ comp",但只有前14个服务器的结果,然后主机线程就在那里.(直到我用火杀死它,我的输出返回到asp.net网页)
当我从asp.net页面运行它时,我无法看到脚本中发生了什么.我可以看到cpu/ram使用率下降到与从PSconsole运行它时相同的水平,但我的主线程从不关闭.所以我确实认为脚本按照假设工作,但我的网页挂起,直到主线程关闭(它从来没有,如上所述).
这就是我调用脚本的方式(不是漂亮的.net <3 powershell方式:)
public string RunProgramme(string scriptpath, string arguments)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"powershell.exe";
startInfo.Arguments = "& \'"+scriptpath+"\' "+ arguments;
//return startInfo.Arguments;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true; …Run Code Online (Sandbox Code Playgroud)