小编wal*_*ybh的帖子

托管PowerShell:PowerShell与Runspace vs. RunspacePool与Pipeline

我试图在我的应用程序中添加一些相当有限的PowerShell支持:我希望能够定期运行用户定义的PowerShell脚本并显示任何输出,并且(最终)能够处理进度通知和用户提示请求.我并不需要命令行式的交互式支持,或(我认为),远程访问或同时运行多个脚本的能力,除非用户脚本做本身从shell我主内.我最终想要异步或在后台线程上运行脚本,并可能与种子一些初始变量和外壳,也许一个小命令但那是因为"看中",因为这功能是可能得到的.

我一直在阅读关于编写主机应用程序代码MSDN文档,但是它很乐意解释如何创建一个PowerShell对象,或者Runspace,或者RunspacePool,或者Pipeline,没有任何迹象表明为什么会选择这些方法而不是另一种方法.

我已经归结为这两个中的一个,但是我想要一些关于哪种方法更好的反馈意见:

PowerShell shell = PowerShell.Create();
shell.AddCommand(/* set initial state here? */);
shell.AddStatement();
shell.AddScript(myScript);
shell.Invoke(/* can set host! */);
Run Code Online (Sandbox Code Playgroud)

要么:

Runspace runspace = RunspaceFactory.CreateRunspace(/* can set host and initial state! */);
PowerShell shell = PowerShell.Create();
shell.Runspace = runspace;
shell.AddScript(myScript);
shell.Invoke(/* can set host here, too! */);
Run Code Online (Sandbox Code Playgroud)

(其中一个必需的PSHost类方法是EnterNestedPrompt(),我不知道我运行的用户定义的脚本是否会导致它被调用.如果可以,那么我将负责"开始一个新的嵌套输入循环"(按照此处)...如果这会影响上面的路径,那么这也是很好的.)

谢谢!

powershell powershell-hosting

17
推荐指数
2
解决办法
6117
查看次数

使PowerShell忽略分号

我想在PowerShell上执行cmd,此命令使用分号.然后PowerShell将其解释为多个命令.如何使PowerShell忽略分号并执行我的命令如何使用唯一命令?

例:

Invoke-Expression "msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Debug;_PackageTempDir=$TargetFolder $WebProject"
Run Code Online (Sandbox Code Playgroud)

另一个例子:

Invoke-Expression "test`;test2"
Run Code Online (Sandbox Code Playgroud)

第二个例子回应:

The term 'test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:6
+ teste <<<< ;teste2
    + CategoryInfo          : ObjectNotFound: (teste:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The term 'test2' is not recognized as the name of a cmdlet, …
Run Code Online (Sandbox Code Playgroud)

powershell

10
推荐指数
3
解决办法
9360
查看次数

使用backgroundworker的多种长方法的最佳实践

我有一个有很多长方法的表单.我的任务是:最佳做法是什么?使用匿名方法和只有一个backgroundworker或为每个long方法创建BackgroundWorker实例.

请帮忙.谢谢.

c# backgroundworker winforms

7
推荐指数
1
解决办法
1967
查看次数

如何在 html 工具提示中转义 html

我正在尝试使用 HTML 打印工具提示,但我需要将其中一些 html 隔开。我尝试了一些东西,但没有成功。

这是我的例子:http : //jsfiddle.net/wrsantos/q3o1e4ut/1/

在这个例子中,我想转义 <code> 中的所有 html。

<span rel="tooltip" 
    data-toggle="tooltip" 
    data-trigger="hover" 
    data-placement="bottom" 
    data-html="true" 
    data-title="<table><tr><td style='color:red;'>complex&nbsp;</td><td>HTML:</td></tr></table><code>&lt;html&gt;</code>">
    hover over me to see html
</span>
Run Code Online (Sandbox Code Playgroud)

Javascript:

$('[rel="tooltip"]').tooltip();
Run Code Online (Sandbox Code Playgroud)

编辑:

不是重复的(我可以在 Twitter Bootstrap 的工具提示中使用复杂的 HTML 吗?

我想要来自 html 和非 html 工具提示的“混合模式”。

在工具提示中,我将拥有风格化内容和非风格化内容(非风格化内容将在 <code> 标签内)。

html javascript twitter-bootstrap-3

6
推荐指数
1
解决办法
5747
查看次数