使用F#脚本在生产环境中替换powershell?(Using F# script replace powershell in production environment?)

编程入门 行业动态 更新时间:2024-10-22 10:40:58
使用F#脚本在生产环境中替换powershell?(Using F# script replace powershell in production environment?)

我一直在使用powershell脚本来自动化生产服务器上的一些任务。 然而,当我尝试做一些关于异步和并行处理的事情时,它就会受到限制。

F#脚本很好地替换PowerShell脚本吗? (当访问文件系统和其他其他OS对象时,这会非常麻烦,这在Powershell中非常简单)。 服务器没有安装visual studio。 是否可以将fsi.exe复制到服务器以运行fsx文件?

用例,

从慢速FTP服务器下载大型压缩文件 解压缩文件 执行可执行文件来处理解压缩的文件

每个步骤都需要一段时间,所以我想要做一些像PowerShell中很难做到的事情

//Limit download 3 files at the same time maximum. async { let! zip = GetFromFTP ... let! file = Unzip zip do! ... //Run exe to parse file }

I've been using powershell script to automate some tasks on production servers. However, it reaches its limitation when I try to do something about async and parallel processing, etc.

Is F# script a good to replace powershell script? (Guess it will be more cumbersome when access file system and other other OS objects, which is very easy in Powershell). The servers don't have visual studio installed. Is it OK just copy fsi.exe to the server to run the fsx files?

A use case,

Download big zip files from a slow FTP server Unzip the files Execute an executable files to process the unzipped files

each steps take a while so I want to do something like the following which is hard to do it in powershell

//Limit download 3 files at the same time maximum. async { let! zip = GetFromFTP ... let! file = Unzip zip do! ... //Run exe to parse file }

最满意答案

F#脚本并不是一个完全替代powershell的好选择 - 正如你所提到的,F#是一种低级语言,所以你需要编写更多的代码来完成基本的系统自动化工作。 F#还没有与其他Windows服务器技术很好地整合,所以这将是另一场艰苦的战斗。 如果你真的想走这条路,你应该在你的服务器上安装F#3.1.2包 ,这将部署FSharp.Core运行时和fsc / fsi。

由于PowerShell和F#都基于.NET,所以另一种选择是将更多的算法计算密集型代码编写成F#作为DLL,然后将其加载到PowerShell中。 您甚至可以直接在F#中编写Powershell cmdlet 。 我过去成功地使用了这种方法。

如果您的具体问题与代码的并行/异步执行相关,那么PowerShell 后台作业可能是相关的。

编辑:关于powershell / F#互操作性的话题, Powershell类型提供者也可能值得研究。

F# script is not a good choice to replace powershell altogether - as you mentioned, F# is a much lower-level language, so you will need to write a ton more code to do basic system automation stuff. F# also isn't as well-integrated with other Windows server technologies, so that will be another uphill battle. If you really want to go that route, you should install the F# 3.1.2 bundle on your server, that will deploy the FSharp.Core runtime and fsc/fsi.

Since both powershell and F# are based on .NET, another option is to write your more algorithmic, computationally intensive code in F# as a DLL, then simply load that into powershell. You can even write Powershell cmdlets directly in F#. I've used this approach successfully in the past.

If your specific question is related to parallel/async execution of code, powershell background jobs might be relevant.

Edit: On the topic of powershell/F# interoperability, the Powershell Type Provider might also be worth investigating.

更多推荐

本文发布于:2023-08-04 06:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   环境   powershell   script   production

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!