小儿支气管哮喘,黄鹤楼香烟漫天游,天堂的树歌曲
我们可以使有dotnetcore跨平台的特性,优雅的实现在dotnetcore执行shell (bash). 代码如下:
using system; using system.collections.generic; using system.text; namespace hshoc { using system.diagnostics; public static class shellhelper { public static string bash(this string cmd) { var escapedargs = cmd.replace("\"", "\\\""); var process = new process() { startinfo = new processstartinfo { filename = "/bin/bash", arguments = $"-c \"{escapedargs}\"", redirectstandardoutput = true, useshellexecute = false, createnowindow = true, } }; process.start(); string result = process.standardoutput.readtoend(); process.waitforexit(); return result; } } }
为什么使用dotnetcore, 其性能比java更好,使用c#的扩展方法, 具体调用上面的代码是
var output = "ps aux".bash();
是不是比较方便。大家可以延伸自动的应用。我们编写更复杂的shell脚本在其中,充分利用c#的特性,快速开发,易于调试。
这也是其中devops过程中很小一个点儿。
今天先到这儿,希望对技术领导力, 企业管理,系统架构设计与评估,团队管理, 项目管理, 产品管理,团队建设 有参考作用 , 您可能感兴趣的文章:
如有想了解更多软件设计与架构, 系统it,企业信息化, 团队管理 资讯,请关注我的微信订阅号:
作者:
出处:
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-petter liu blog。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论