Reputation: 135
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.
Upvotes: 1
Views: 156
Reputation: 135
I resolved this using a bat file which did not need admin permissions to run from the C# code. and using the call command to execute another batch file from a batch file. I also used another SO post to use a relative path file in a batch file.
Upvotes: 1