我试图在我的应用程序中添加一些相当有限的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(),我不知道我运行的用户定义的脚本是否会导致它被调用.如果可以,那么我将负责"开始一个新的嵌套输入循环"(按照此处)...如果这会影响上面的路径,那么这也是很好的.)
谢谢!
warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
Run Code Online (Sandbox Code Playgroud)
Shouldn't a float be able to handle any value from an int?
unsigned int: 0 to 4,294,967,295
float 3.4E +/- 38 (7 digits)
Run Code Online (Sandbox Code Playgroud)
Wiki:
Run Code Online (Sandbox Code Playgroud)The advantage of floating-point representation over fixed-point (andinteger) representation is that it can support a much wider range of values.
Any insight would be helpful, thanks.
http://msdn.microsoft.com/en-us/library/s3f49ktz%28VS.80%29.aspx