首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在没有管理员权限的情况下从C#使用Git-bash

在没有管理员权限的情况下从C#使用Git-bash
EN

Stack Overflow用户
提问于 2021-06-08 22:43:52
回答 1查看 57关注 0票数 1

我正在尝试启动一个python虚拟环境,并使用以下代码从C#文件运行python文件。

代码语言:javascript
复制
public static void ExecuteGitBashCommand(string fileName, string command, string workingDir)
    {

        ProcessStartInfo processStartInfo = new ProcessStartInfo(fileName, "-c \" " + command + " \"")
        {
            WorkingDirectory = workingDir,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            RedirectStandardInput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };

        var process = Process.Start(processStartInfo);
        process.WaitForExit();

        string output = process.StandardOutput.ReadToEnd();
        string error = process.StandardError.ReadToEnd();
        var exitCode = process.ExitCode;

        process.Close();
    }

在运行时,我得到了一个错误,说"System.ComponentModel.Win32Exception:‘访问被拒绝’“。环顾四周,我看到的建议是以管理员身份运行,但这不是一个选项。有没有办法在没有那个的情况下做到这一点?运行代码的用户有权运行git-bash。

编辑1:

我开始研究使用一个.BAT文件,但是为了达到这个目的,我需要使用一个bat,第二个bat文件,它激活了虚拟环境,导致它不能运行bat文件的第二部分。无论如何,让它在同一命令提示符上执行这两个命令可以解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-09 04:07:31

我使用一个bat文件解决了这个问题,该文件不需要管理员权限即可从C#代码运行。以及使用call命令从批处理文件执行另一个批处理文件。我还使用了另一个SO post来使用批处理文件中的相对路径文件。

relative path in BAT script

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67889320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档