什么是须藤在MSYS等价?

编程入门 行业动态 更新时间:2024-10-26 06:27:35
本文介绍了什么是须藤在MSYS等价?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在写的应该在Unix上,Cygwin的,和MSYS工作一个跨平台的shell脚本。在我的shell脚本我需要执行与提升权限的操作。在Unix上,你将通过须藤做到这一点,并在的 Cygwin的通过类似 cygstart --action =运行方式 。什么是对MSYS等价?

I'm writing a cross-platform shell script that's supposed to work on Unix, Cygwin, and msys. In my shell script I need to perform actions with elevated privileges. On Unix you would do this via sudo, and on Cygwin via something like cygstart --action=runas. What's the equivalent for msys?

我所有的谷歌搜索至今只止跌回升这,这是不实际的距离一个shell脚本,因为你必须与GUI交互。

All my Googling so far has only turned up this, which isn't practical from a shell script since you have to interact with the GUI.

推荐答案

我想我可能已经找到使用PowerShell的一个解决方案:

I think I may have found a solution using PowerShell:

escape() { RESULT="$1" RESULT="${RESULT/\'/\\\'\'}" # replace ' with \'' RESULT="${RESULT/\"/\\\\\\\"}" # replace " with \\\" echo "''$RESULT''" # PowerShell uses '' to escape ' } sudo() { ESCAPED=() for ARG in "$@" do ESCAPED+=($(escape "$ARG")) done SHELL_PATH=$(cygpath -w $SHELL) PS_COMMAND="[Console]::In.ReadToEnd() | Start-Process '$SHELL_PATH' '-c -- \"${ESCAPED[*]}\"' -Verb RunAs" cat /dev/stdin | powershell -NoProfile -ExecutionPolicy Bypass "$PS_COMMAND" }

绝对是位非常的hackish,但总比没有好。 (或批处理文件,为这一问题。)

Definitely a bit Extremely hackish, but it's better than nothing. (Or Batch files, for that matter.)

更多推荐

什么是须藤在MSYS等价?

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

发布评论

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

>www.elefans.com

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