My original question was "C# run Pip install in Venv programmatically" but it turns out there was no issue with C# code or the Pip thing. But with the Batch Script. SO first is the edited question to help others and then my original question for just a record.
Run a Batch script with a command to run another Batch file.
child.bat
@echo off
echo Child Batch File is running !!!
echo Doing some Important Child Batch Stuff here . . . .
echo ✔ Child Batch Completed it. Voila !!
echo Now exiting Child.bat
parent.bat
@echo off
echo Parent Batch File is running !!!
echo Doing some Important Stuff here . . . .
echo ✔ Completed it. Voila !!
echo Now running Child.bat . . .
echo -------------------------------------------------------
child.bat
// Comment: Some how below statements are not executing
echo -------------------------------------------------------
echo ✔ Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.
Output:
C:\Users\abc> parent.bat
Parent Batch File is running !!!
Doing some Important Stuff here . . . .
✔ Completed it. Voila !!. .
Now running Child.bat . . .
-------------------------------------------------------
Child Batch File is running !!!
Doing some Important Child Batch Stuff here . . . .
✔ Child Batch Completed it. Voila !!
Now exiting Child.bat
C:\Users\abc>
Where are the other parent.bat echo commands.
Expected Output:
Parent Batch File is running !!!
Doing some Important Stuff here . . . .
✔ Completed it. Voila !!. .
Now running Child.bat . . .
-------------------------------------------------------
Child Batch File is running !!!
Doing some Important Child Batch Stuff here . . . .
✔ Child Batch Completed it. Voila !!
Now exiting Child.bat
-------------------------------------------------------
Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.
Old Question for just a record
I have a C# application and it uses some python scripts. To run the python scripts I need to have some dependencies. So i created a batch file that creates a VENV. But it never runs PIP INSTALL COMMAND.
C# Code to run multiple cmd statements. It creates a batch file.
public void abc() {
var batFileName = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.bat");
using (var batFile = new StreamWriter(batFileName))
{
var pythonPath = Path.Combine(LocalAppData, ProjectGuid, HolocronFolders["HolocronPython"]);
var venv = Path.Combine(LocalAppData, ProjectGuid, HolocronFolders["HolocronVenv"]);
batFile.WriteLine($"{pythonPath}\\python.exe -m venv {venv}");
batFile.WriteLine($"{venv}\\Scripts\\activate.bat");
batFile.WriteLine($"pip install rich"); // Not running in venv
}
var process = new Process();
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C {batFileName}"
};
process.StartInfo = startInfo;
process.Start();
File.Delete(batFileName);
}
batch file created
Path_to_python\python.exe -m venv path_to_venv_folder
Path_to_venv_folder\Scripts\activate.bat
pip install rich --//-- Comments: Not running in Venv. Actually not running at all.
cmd output:
c:\user\abc> Path_to_python\python.exe -m venv path_to_venv_folder
c:\user\abc> Path_to_venv_folder\Scripts\activate.bat
(path_to_venv_folder) c:\user\abc>