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
Should be as simple as running the script in a
Process
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 Pythonits more a testing thing
I see
and how does process work?
tried some things
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
or python3, etc
1st parameter is the file, 2nd is the arguments
yes thanks!!!
finally works. Thank you so much!
Just remember that the method will fail if there is no python installed
And how can I make it work if I want it to always work?
<: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#
Embed an archive of python3. Unpack it when your app starts. Lol
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")