我在从另一个 powershell 脚本中运行 powershell 脚本、传递参数和捕获输出时遇到问题。我曾尝试使用与号运算符,通过调用它powershell.exe -Command但似乎没有任何效果。
似乎有效的是使用固定参数和存储在这样的变量中的值C:\path\to\script.ps1 -arg1 $value。
如果没有其他方法,这可能会提供一个解决方案,但我想运行与此类似的命令& $pathToScript $params 2>&1(2>&1用于捕获错误输出以及标准)。
有时构造只打印脚本的路径,
有时它会说Cannot run file in the middle of pipeline,
有时它会抱怨它找不到提到的脚本文件(我有时在我的路径中有空格,但我认为引用它就足够了:引用是这样完成的$path = "`"C:\path\with space\to\script.ps1`"")。
这是我想在以下情况下使用的简化函数:
Function captureScriptOutput
{
#the function receives the script path and parameters
param($path, $params)
#this works if no params are passed, but I need params!
$output = & $path $params 2>&1 | Out-String
}
Run Code Online (Sandbox Code Playgroud) I need the "Job Setup Sheet" centered under the Heading. How should that be done?
Here is what I tried:
// Create an empty page
PdfPage page = document.AddPage();
page.Size = PageSize.Letter;
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
//XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode,
PdfFontEmbedding.Always);
// Create a font
XFont HeadingFont = new XFont("Times New Roman", 20, XFontStyle.Bold);
XFont BodyFont = new XFont("Times New Roman", 12);
// Draw the text
gfx.DrawString("Texas Exterior Systems", HeadingFont, XBrushes.Black,
new …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用C#在运行空间中执行带有参数的Powershell文件.不幸的是我得到以下输出:
public string ExecuteCommandDirect(int psId, string psMaster, string psFile)
{
String FullPsFilePath = @"C:\CloudPS\" + psFile + ".ps1";
String PsParameters = FullPsFilePath + " -psId " + psId + " -psMaster " + psMaster + " -NonInteractive";
// Create Powershell Runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
// Create pipeline and add commands
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(PsParameters);
// Execute Script
Collection<PSObject> results = new Collection<PSObject>();
try
{
results = pipeline.Invoke();
}
catch (Exception ex)
{
results.Add(new PSObject((object)ex.Message));
}
// Close …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个程序来解析游戏聊天记录中的数据.到目前为止,我已经设法让程序工作并解析我想要的数据,但问题是程序变慢了.
目前解析一个10MB的文本文件需要5秒钟,如果我将RegexOptions.Compiled添加到我的正则表达式,我注意到它下降到3秒.
我相信我已经在我的正则表达式匹配中找到了问题.由于5个正则表达式,当前读取了一行5次,因此当我稍后添加更多时,程序会变得更慢.
我应该怎么做才能使我的程序不会因多个正则表达式而减速?所有建议,使代码更好的表示赞赏!
if (sender.Equals(ButtonParse))
{
var totalShots = 0f;
var totalHits = 0f;
var misses = 0;
var crits = 0;
var regDmg = new Regex(@"(?<=\bSystem\b.* You inflicted )\d+.\d", RegexOptions.Compiled);
var regMiss = new Regex(@"(?<=\bSystem\b.* Target evaded attack)", RegexOptions.Compiled);
var regCrit = new Regex(@"(?<=\bSystem\b.* Critical hit - additional damage)", RegexOptions.Compiled);
var regHeal = new Regex(@"(?<=\bSystem\b.* You healed yourself )\d+.\d", RegexOptions.Compiled);
var regDmgrec = new Regex(@"(?<=\bSystem\b.* You take )\d+.\d", RegexOptions.Compiled);
var dmgList = new List<float>(); //New list for damage …Run Code Online (Sandbox Code Playgroud) 给定以下正则表达式正则表达式(从我实际上想使用的正则表达式简化):
(?<=\s|\n)(".*?")
Run Code Online (Sandbox Code Playgroud)
和以下替换表达式:
_T($1)
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2013将找到每个匹配的字符串,但是在替换时,将替换与后续匹配相对应的字符串,因此将替换第二个字符串。
此外,Replace All它不起作用,并说它找不到任何匹配的文本(即使a Find All会找到相关的字符串)。
这是Visual Studio中的错误,还是我做错了什么?
演示:

我有一个我正在使用的事件,所以我真的不明白这个警告的真正含义.有人可以澄清吗?
public abstract class Actor<T> : Visual<T> where T : ActorDescription
{
#region Events
/// <summary>
/// Event occurs when the actor is dead
/// </summary>
public event Action Dead;
#endregion
/// <summary>
/// Take damage if the actor hasn't taken damage within a time limit
/// </summary>
/// <param name="damage">amount of damage</param>
public void TakeDamage(int damage)
{
if (damage > 0 && Time.time > m_LastHitTimer + m_DamageHitDelay)
{
m_CurrentHealth -= damage;
if (m_CurrentHealth <= 0)
{
m_CurrentHealth = 0; …Run Code Online (Sandbox Code Playgroud) 我正在编写一个WPF用户控件,它显示一个包含多个页面的动态生成的TabControl,每个页面依次包含一个动态生成的控件列表(TextBox,Checkbox等).
我想根据用户是否有权查看它们来设置TextBox,CheckBox控件的可见性.此权限是每个控件ViewModel('VisiblyBy')上的值的组合,也是整个UserControl ViewModel('UserRole')的属性的组合.我刚刚开始使用WPF,但标准方法似乎是使用ValueConvertor - 但我不明白我如何编写一个可以组合/访问不同属性(VisiblyBy和UserRole)的方法,因为它们存在于不同的级别在我的ViewModel文件中.
这是我绑定到ViewModel的XAML的一部分:
<TabControl ItemsSource="{Binding VariableData.Pages}" SelectedIndex="0">
<!-- this is the header template-->
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" FontWeight="Bold"/>
</DataTemplate>
</TabControl.ItemTemplate>
<!-- this is the tab content template-->
<TabControl.ContentTemplate>
<DataTemplate>
<StackPanel>
<ListBox Grid.IsSharedSizeScope="True"
ItemsSource="{Binding Variables}"
ItemTemplateSelector="{StaticResource templateSelector}">
</ListBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="Cancel" />
<Button Content="Submit"
Command="{Binding DataContext.CommitChangesCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type TabControl}}}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>Run Code Online (Sandbox Code Playgroud)
我还需要扩展控制未来可见性的变量数量,因为它还取决于使用它的应用程序的位置.
我有一个大型 VS 解决方案,但我只处理两个不同的项目,但需要加载所有项目才能进行构建。
是否可以只查看我感兴趣的项目而不更改解决方案的结构以进行构建?
如果不可能,但有解决方法吗?
我有一个这样的字符串:
string myText = "abc def ghi 123 abc def ghi 123 abc def";
Run Code Online (Sandbox Code Playgroud)
我只想abc用空替换最后一个。
这是我的代码:
string pattern2 = "([abc])$";
string replacement2 = "";
Regex regEx = new Regex(pattern2);
var b = Regex.Replace(regEx.Replace(myText, replacement2), @"\s", " ");
Run Code Online (Sandbox Code Playgroud)
它不能正常工作,那么如何才能做到呢?
当我尝试通过使用APIM在APIM中创建API时Create from Function App,我填写了字段并单击Create。该操作会提供等待点,并在五秒钟后返回并说
无法创建API。请稍后再试。
我可以创建一个空白的API,但是不能从现有的功能应用程序中创建一个。我尝试了多种组合,没有产品,所有产品,没有版本,版本..etc。没运气。
有什么想法吗?
笔记