C
C#2y ago
bribri

start an python script from an c# project

How can I start my python script from an c# project? My solution looks like this at the moment but not really sure how to let it run ( i'm testing some things so my solution explorer looks really bad....)
15 Replies
HimmDawg
HimmDawg2y ago
Should be as simple as running the script in a Process fluffyFoxThink
Chiyoko_S
Chiyoko_S2y ago
yeah just run the python script using the python interpreter you can do that in C# using Process although it is questionable why you'd want to do that? is it not possible to just have everything in C# or Python
bribri
bribriOP2y ago
its more a testing thing
Chiyoko_S
Chiyoko_S2y ago
I see
bribri
bribriOP2y ago
and how does process work? tried some things
Chiyoko_S
Chiyoko_S2y ago
it is pretty similar to how you execute files in command line you have a program, and you feed it arguments / etc to it to start executing in this case the program would be the python interpreter
bribri
bribriOP2y ago
arion
arion2y ago
Process.Start("py", "myscript.py");
Process.Start("py", "myscript.py");
or python3, etc 1st parameter is the file, 2nd is the arguments
bribri
bribriOP2y ago
yes thanks!!! finally works. Thank you so much!
arion
arion2y ago
Just remember that the method will fail if there is no python installed
bribri
bribriOP2y ago
And how can I make it work if I want it to always work?
arion
arion2y ago
<:poi_shrug:582941309174546569> Ensure python is installed before running the method There's also other libraries like IronPython though I've never used python in c#
phaseshift
phaseshift2y ago
Embed an archive of python3. Unpack it when your app starts. Lol
arion
arion2y ago
If you've never done embedding files into your program before, this tutorial explains pretty much exactly what you'd need to do https://www.c-sharpcorner.com/UploadFile/40e97e/saving-an-embedded-file-in-C-Sharp/ (Skip the first step of course "Step 1. Create a new Console Application")
Want results from more Discord servers?
Add your server