I was trying to start a python virtual environment and run a python file from a C# file using the below code.
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();
}
Upon running I get an error that says "System.ComponentModel.Win32Exception: 'Access is denied.'" Looking around the recommendations I see are to run as an Administrator but that is not an option. Is there a way to do this without that? The user running the code has the permissions to run git-bash.
EDIT 1:
I started looking into using a .BAT file but to do that I need to use a bat a second bat file that activates the virtual environment which caused it to not run the second part of the bat file. Anyway to get it to execute both of those commands on the same command prompt would fix the problem.